From d6a3f2d3d519f6a3c1eb248a38706f7df9f4e69c Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 21 Dec 2023 18:46:50 -0700 Subject: [PATCH] Fix generator for aggregations --- xarray/core/_aggregations.py | 80 +++++++++++++++++++++++----- xarray/util/generate_aggregations.py | 26 +++++++++ 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index ff8e62121f3..0d4b4413b7c 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -2315,6 +2315,19 @@ def cumprod( class DatasetGroupByAggregations: _obj: Dataset + def _reduce_without_squeeze_warn( + self, + func: Callable[..., Any], + dim: Dims = None, + *, + axis: int | Sequence[int] | None = None, + keep_attrs: bool | None = None, + keepdims: bool = False, + shortcut: bool = True, + **kwargs: Any, + ) -> Dataset: + raise NotImplementedError() + def reduce( self, func: Callable[..., Any], @@ -3829,6 +3842,19 @@ def cumprod( class DatasetResampleAggregations: _obj: Dataset + def _reduce_without_squeeze_warn( + self, + func: Callable[..., Any], + dim: Dims = None, + *, + axis: int | Sequence[int] | None = None, + keep_attrs: bool | None = None, + keepdims: bool = False, + shortcut: bool = True, + **kwargs: Any, + ) -> Dataset: + raise NotImplementedError() + def reduce( self, func: Callable[..., Any], @@ -5112,21 +5138,21 @@ def median( >>> ds.resample(time="3M").median() - Dimensions: (__resample_dim__: 3) + Dimensions: (time: 3) Coordinates: - * __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0... + * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (__resample_dim__) float64 1.0 2.0 2.0 + da (time) float64 1.0 2.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3M").median(skipna=False) - Dimensions: (__resample_dim__: 3) + Dimensions: (time: 3) Coordinates: - * __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0... + * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (__resample_dim__) float64 1.0 2.0 nan + da (time) float64 1.0 2.0 nan """ return self._reduce_without_squeeze_warn( duck_array_ops.median, @@ -5343,6 +5369,19 @@ def cumprod( class DataArrayGroupByAggregations: _obj: DataArray + def _reduce_without_squeeze_warn( + self, + func: Callable[..., Any], + dim: Dims = None, + *, + axis: int | Sequence[int] | None = None, + keep_attrs: bool | None = None, + keepdims: bool = False, + shortcut: bool = True, + **kwargs: Any, + ) -> DataArray: + raise NotImplementedError() + def reduce( self, func: Callable[..., Any], @@ -6749,6 +6788,19 @@ def cumprod( class DataArrayResampleAggregations: _obj: DataArray + def _reduce_without_squeeze_warn( + self, + func: Callable[..., Any], + dim: Dims = None, + *, + axis: int | Sequence[int] | None = None, + keep_attrs: bool | None = None, + keepdims: bool = False, + shortcut: bool = True, + **kwargs: Any, + ) -> DataArray: + raise NotImplementedError() + def reduce( self, func: Callable[..., Any], @@ -7936,18 +7988,18 @@ def median( labels (time) >> da.resample(time="3M").median() - + array([1., 2., 2.]) Coordinates: - * __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0... + * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3M").median(skipna=False) - + array([ 1., 2., nan]) Coordinates: - * __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0... + * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 """ return self._reduce_without_squeeze_warn( duck_array_ops.median, @@ -8034,8 +8086,8 @@ def cumsum( array([1., 2., 5., 5., 2., 2.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) array([ 1., 2., 5., 5., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) array([1., 2., 6., 0., 2., 2.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) array([ 1., 2., 6., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) {obj}: + raise NotImplementedError() + def reduce( self, func: Callable[..., Any], @@ -113,6 +126,19 @@ def _flox_reduce( class {obj}{cls}Aggregations: _obj: {obj} + def _reduce_without_squeeze_warn( + self, + func: Callable[..., Any], + dim: Dims = None, + *, + axis: int | Sequence[int] | None = None, + keep_attrs: bool | None = None, + keepdims: bool = False, + shortcut: bool = True, + **kwargs: Any, + ) -> {obj}: + raise NotImplementedError() + def reduce( self, func: Callable[..., Any],