diff --git a/doc/conf.py b/doc/conf.py index e5e0b69e765..d0a26e19a84 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -158,6 +158,8 @@ "Variable": "~xarray.Variable", "DatasetGroupBy": "~xarray.core.groupby.DatasetGroupBy", "DataArrayGroupBy": "~xarray.core.groupby.DataArrayGroupBy", + "Grouper": "~xarray.core.groupers.Grouper", + "Resampler": "~xarray.core.groupers.Resampler", # objects without namespace: numpy "ndarray": "~numpy.ndarray", "MaskedArray": "~numpy.ma.MaskedArray", diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index eec1c182a0e..b62189c3aa1 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -6684,7 +6684,7 @@ def interp_calendar( def groupby( self, group: ( - Hashable | DataArray | IndexVariable | Mapping[Hashable, Grouper] | None + Hashable | DataArray | IndexVariable | Mapping[Any, Grouper] | None ) = None, squeeze: bool | None = None, restore_coord_dims: bool = False, @@ -6694,9 +6694,10 @@ def groupby( Parameters ---------- - group : Hashable, DataArray or IndexVariable + group : Hashable or DataArray or IndexVariable or mapping of Hashable to Grouper Array whose unique values should be used to group this array. If a - Hashable, must be the name of a coordinate contained in this dataarray. + Hashable, must be the name of a coordinate contained in this dataarray. If a dictionary, + must map an existing variable name to a :py:class:`Grouper` instance. squeeze : bool, default: True If "group" is a dimension of any arrays in this dataset, `squeeze` controls whether the subarrays have a dimension of length 1 along @@ -6704,8 +6705,8 @@ def groupby( restore_coord_dims : bool, default: False If True, also restore the dimension order of multi-dimensional coordinates. - **groupers : Mapping of hashable to Grouper or Resampler - Mapping of variable name to group by to ``Grouper`` or ``Resampler`` object. + **groupers : Mapping of str to Grouper or Resampler + Mapping of variable name to group by to :py:class:`Grouper` or :py:class:`Resampler` object. One of ``group`` or ``groupers`` must be provided. Only a single ``grouper`` is allowed at present. @@ -6775,7 +6776,7 @@ def groupby( _validate_groupby_squeeze(squeeze) if isinstance(group, Mapping): - groupers = either_dict_or_kwargs(group, groupers, "groupby") + groupers = either_dict_or_kwargs(group, groupers, "groupby") # type: ignore group = None grouper: Grouper diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index fc02d4f712c..e69a3664414 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -10258,7 +10258,7 @@ def interp_calendar( def groupby( self, group: ( - Hashable | DataArray | IndexVariable | Mapping[Hashable, Grouper] | None + Hashable | DataArray | IndexVariable | Mapping[Any, Grouper] | None ) = None, squeeze: bool | None = None, restore_coord_dims: bool = False, @@ -10268,9 +10268,10 @@ def groupby( Parameters ---------- - group : Hashable, DataArray or IndexVariable + group : Hashable or DataArray or IndexVariable or mapping of Hashable to Grouper Array whose unique values should be used to group this array. If a - string, must be the name of a variable contained in this dataset. + Hashable, must be the name of a coordinate contained in this dataarray. If a dictionary, + must map an existing variable name to a :py:class:`Grouper` instance. squeeze : bool, default: True If "group" is a dimension of any arrays in this dataset, `squeeze` controls whether the subarrays have a dimension of length 1 along @@ -10278,8 +10279,8 @@ def groupby( restore_coord_dims : bool, default: False If True, also restore the dimension order of multi-dimensional coordinates. - **groupers : Mapping of hashable to Grouper or Resampler - Mapping of variable name to group by to ``Grouper`` or ``Resampler`` object. + **groupers : Mapping of str to Grouper or Resampler + Mapping of variable name to group by to :py:class:`Grouper` or :py:class:`Resampler` object. One of ``group`` or ``groupers`` must be provided. Only a single ``grouper`` is allowed at present. @@ -10318,7 +10319,7 @@ def groupby( _validate_groupby_squeeze(squeeze) if isinstance(group, Mapping): - groupers = either_dict_or_kwargs(group, groupers, "groupby") + groupers = either_dict_or_kwargs(group, groupers, "groupby") # type: ignore group = None if group is not None: @@ -10613,7 +10614,7 @@ def coarsen( def resample( self, - indexer: Mapping[Hashable, str | Resampler] | None = None, + indexer: Mapping[Any, str | Resampler] | None = None, skipna: bool | None = None, closed: SideOptions | None = None, label: SideOptions | None = None,