@@ -320,7 +320,7 @@ def pipe(self, func, *args, **kwargs):
320
320
else :
321
321
return func (self , * args , ** kwargs )
322
322
323
- def groupby (self , group , squeeze = True , bins = None ):
323
+ def groupby (self , group , squeeze = True ):
324
324
"""Returns a GroupBy object for performing grouped operations.
325
325
326
326
Parameters
@@ -332,26 +332,67 @@ def groupby(self, group, squeeze=True, bins=None):
332
332
If "group" is a dimension of any arrays in this dataset, `squeeze`
333
333
controls whether the subarrays have a dimension of length 1 along
334
334
that dimension or if the dimension is squeezed out.
335
- bins : array-like, optional
336
- If `bins` is specified, the groups will be discretized into the
337
- specified bins determined by `pandas.cut` applied to the index of
338
- `group`.
339
335
340
336
Returns
341
337
-------
342
338
grouped : GroupBy
343
339
A `GroupBy` object patterned after `pandas.GroupBy` that can be
344
340
iterated over in the form of `(unique_value, grouped_array)` pairs.
345
-
346
- See Also
347
- --------
348
- pandas.cut
349
341
"""
350
- from .dataarray import DataArray
342
+ if isinstance (group , basestring ):
343
+ group = self [group ]
344
+ return self .groupby_cls (self , group , squeeze = squeeze )
345
+
346
+ def groupby_bins (self , group , bins , right = True , labels = None , precision = 3 ,
347
+ include_lowest = False , squeeze = True ):
348
+ """Returns a GroupBy object for performing grouped operations. Rather
349
+ than using all unique values of `group`, the values are discretized
350
+ first by applying `pandas.cut` [1]_ to `group`.
351
351
352
+ Parameters
353
+ ----------
354
+ group : str, DataArray or Coordinate
355
+ Array whose binned values should be used to group this array. If a
356
+ string, must be the name of a variable contained in this dataset.
357
+ bins : int or array of scalars
358
+ If bins is an int, it defines the number of equal-width bins in the
359
+ range of x. However, in this case, the range of x is extended by .1%
360
+ on each side to include the min or max values of x. If bins is a
361
+ sequence it defines the bin edges allowing for non-uniform bin
362
+ width. No extension of the range of x is done in this case.
363
+ right : boolean, optional
364
+ I ndicates whether the bins include the rightmost edge or not. If
365
+ right == True (the default), then the bins [1,2,3,4] indicate
366
+ (1,2], (2,3], (3,4].
367
+ labels : array or boolean, default None
368
+ Used as labels for the resulting bins. Must be of the same length as
369
+ the resulting bins. If False, string bin labels are assigned by
370
+ `pandas.cut`.
371
+ precision : int
372
+ The precision at which to store and display the bins labels.
373
+ include_lowest : bool
374
+ Whether the first interval should be left-inclusive or not.
375
+ squeeze : boolean, optional
376
+ If "group" is a dimension of any arrays in this dataset, `squeeze`
377
+ controls whether the subarrays have a dimension of length 1 along
378
+ that dimension or if the dimension is squeezed out.
379
+
380
+ Returns
381
+ -------
382
+ grouped : GroupBy
383
+ A `GroupBy` object patterned after `pandas.GroupBy` that can be
384
+ iterated over in the form of `(unique_value, grouped_array)` pairs.
385
+
386
+ References
387
+ ----------
388
+ .. [1] http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html
389
+ """
352
390
if isinstance (group , basestring ):
353
391
group = self [group ]
354
- return self .groupby_cls (self , group , squeeze = squeeze , bins = bins )
392
+ return self .groupby_cls (self , group , squeeze = squeeze , bins = bins ,
393
+ cut_kwargs = {'right' : right , 'labels' : labels ,
394
+ 'precision' : precision ,
395
+ 'include_lowest' : include_lowest })
355
396
356
397
def rolling (self , min_periods = None , center = False , ** windows ):
357
398
"""
0 commit comments