diff --git a/doc/user-guide/groupby.rst b/doc/user-guide/groupby.rst index 6c7834cfc90..44b6f99f083 100644 --- a/doc/user-guide/groupby.rst +++ b/doc/user-guide/groupby.rst @@ -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. @@ -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 @@ -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)