diff --git a/xarray/core/common.py b/xarray/core/common.py index 6c8fff37580..464cf9d315a 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -38,6 +38,7 @@ from xarray.core.dataarray import DataArray from xarray.core.dataset import Dataset + from xarray.core.groupers import Resampler from xarray.core.indexes import Index from xarray.core.resample import Resample from xarray.core.rolling_exp import RollingExp @@ -876,7 +877,7 @@ def rolling_exp( def _resample( self, resample_cls: type[T_Resample], - indexer: Mapping[Any, str] | None, + indexer: Mapping[Hashable, str | Resampler] | None, skipna: bool | None, closed: SideOptions | None, label: SideOptions | None, @@ -885,7 +886,7 @@ def _resample( origin: str | DatetimeLike, loffset: datetime.timedelta | str | None, restore_coord_dims: bool | None, - **indexer_kwargs: str, + **indexer_kwargs: str | Resampler, ) -> T_Resample: """Returns a Resample object for performing resampling operations. @@ -1098,6 +1099,7 @@ def _resample( name=RESAMPLE_DIM, ) + grouper: Resampler if isinstance(freq, str): grouper = TimeResampler( freq=freq, diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 790ca0f4702..e6ca2ef773b 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -87,7 +87,7 @@ from xarray.backends import ZarrStore from xarray.backends.api import T_NetcdfEngine, T_NetcdfTypes from xarray.core.groupby import DataArrayGroupBy - from xarray.core.groupers import Grouper + from xarray.core.groupers import Grouper, Resampler from xarray.core.resample import DataArrayResample from xarray.core.rolling import DataArrayCoarsen, DataArrayRolling from xarray.core.types import ( @@ -7216,7 +7216,7 @@ def coarsen( def resample( self, - indexer: Mapping[Any, str] | None = None, + indexer: Mapping[Hashable, str | Resampler] | None = None, skipna: bool | None = None, closed: SideOptions | None = None, label: SideOptions | None = None, @@ -7225,7 +7225,7 @@ def resample( origin: str | DatetimeLike = "start_day", loffset: datetime.timedelta | str | None = None, restore_coord_dims: bool | None = None, - **indexer_kwargs: str, + **indexer_kwargs: str | Resampler, ) -> DataArrayResample: """Returns a Resample object for performing resampling operations. diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 55828bae780..e6f7bdf3333 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -137,7 +137,7 @@ from xarray.backends.api import T_NetcdfEngine, T_NetcdfTypes from xarray.core.dataarray import DataArray from xarray.core.groupby import DatasetGroupBy - from xarray.core.groupers import Grouper + from xarray.core.groupers import Grouper, Resampler from xarray.core.merge import CoercibleMapping, CoercibleValue, _MergeResult from xarray.core.resample import DatasetResample from xarray.core.rolling import DatasetCoarsen, DatasetRolling @@ -10600,7 +10600,7 @@ def coarsen( def resample( self, - indexer: Mapping[Any, str] | None = None, + indexer: Mapping[Hashable, str | Resampler] | None = None, skipna: bool | None = None, closed: SideOptions | None = None, label: SideOptions | None = None, @@ -10609,7 +10609,7 @@ def resample( origin: str | DatetimeLike = "start_day", loffset: datetime.timedelta | str | None = None, restore_coord_dims: bool | None = None, - **indexer_kwargs: str, + **indexer_kwargs: str | Resampler, ) -> DatasetResample: """Returns a Resample object for performing resampling operations.