Skip to content

Commit

Permalink
Add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Sep 19, 2024
1 parent f56dc85 commit 17b7f2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doc/user-guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ is identical to
ds.resample(time=TimeResampler("ME"))
The :py:class:`groupers.UniqueGrouper` accepts an optional ``labels`` kwarg that is not present
in :py:meth:`DataArray.groupby` or :py:meth:`Dataset.groupby`.
Specifying ``labels`` is required when grouping by a lazy array type (e.g. dask or cubed).
The ``labels`` are used to construct the output coordinate (say for a reduction), and aggregations
will only be run over the specified labels.
You may use ``labels`` to also specify the ordering of groups to be used during iteration.
The order will be preserved in the output.


.. _groupby.multiple:

Grouping by multiple variables
Expand Down
12 changes: 11 additions & 1 deletion xarray/groupers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,17 @@ class Resampler(Grouper):

@dataclass
class UniqueGrouper(Grouper):
"""Grouper object for grouping by a categorical variable."""
"""
Grouper object for grouping by a categorical variable.
Parameters
----------
labels: array-like, optional
Group labels to aggregate on. This is required when grouping by a chunked array type
(e.g. dask or cubed) since it is used to construct the coordinate on the output.
Grouped operations will only be run on the specified group labels. Any group that is not
present in ``labels`` will be ignored.
"""

_group_as_index: pd.Index | None = field(default=None, repr=False)
labels: np.ndarray | None = field(default=None)
Expand Down

0 comments on commit 17b7f2f

Please sign in to comment.