Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Apr 19, 2024
1 parent aba840a commit 2600219
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions doc/user-guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ applying your function, and then unstacking the result:
Extending GroupBy: Grouper Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. currentmodule:: xarray.core.groupers

The first step in executing a GroupBy analysis is to *identify* the groups and create an intermediate array where each group member is identified
by a unique integer code. Commonly this step is executed using :py:func:`pandas.factorize` for grouping by a categorical variable (e.g. ``['a', 'b', 'a', 'b']``)
and :py:func:`pandas.cut` or :py:func:`numpy.digitize` or :py:func:`numpy.searchsorted` for binning a numeric variable.
Expand All @@ -252,9 +254,9 @@ Eventually, they will also provide a natural way to extend GroupBy to grouping b

Xarray provides three Grouper objects today

1. :py:class:`groupers.UniqueGrouper` for categorical grouping
2. :py:class:`groupers.BinGrouper` for binned grouping
3. :py:class:`groupers.TimeResampler` for resampling along a datetime coordinate
1. :py:class:`UniqueGrouper` for categorical grouping
2. :py:class:`BinGrouper` for binned grouping
3. :py:class:`TimeResampler` for resampling along a datetime coordinate

These objects mean that

Expand All @@ -276,14 +278,9 @@ an instance of :py:class:`EncodedGroups`.

.. ipython:: python
import numpy as np
from xarray.groupers import Grouper, EncodedGroups
class YearGrouper(Grouper):
def factorize(self, group) -> EncodedGroups:
class YearGrouper(xr.groupers.Grouper):
def factorize(self, group) -> xr.groupers.EncodedGroups:
assert np.issubdtype(group.dtype, np.datetime64)
year = group.dt.year
codes, uniques = pd.factorize(year)
return EncodedGroups(codes=codes)

0 comments on commit 2600219

Please sign in to comment.