Skip to content
forked from pydata/xarray

Commit d6a3f2d

Browse files
committed
Fix generator for aggregations
1 parent 97f1695 commit d6a3f2d

File tree

2 files changed

+92
-14
lines changed

2 files changed

+92
-14
lines changed

xarray/core/_aggregations.py

+66-14
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,19 @@ def cumprod(
23152315
class DatasetGroupByAggregations:
23162316
_obj: Dataset
23172317

2318+
def _reduce_without_squeeze_warn(
2319+
self,
2320+
func: Callable[..., Any],
2321+
dim: Dims = None,
2322+
*,
2323+
axis: int | Sequence[int] | None = None,
2324+
keep_attrs: bool | None = None,
2325+
keepdims: bool = False,
2326+
shortcut: bool = True,
2327+
**kwargs: Any,
2328+
) -> Dataset:
2329+
raise NotImplementedError()
2330+
23182331
def reduce(
23192332
self,
23202333
func: Callable[..., Any],
@@ -3829,6 +3842,19 @@ def cumprod(
38293842
class DatasetResampleAggregations:
38303843
_obj: Dataset
38313844

3845+
def _reduce_without_squeeze_warn(
3846+
self,
3847+
func: Callable[..., Any],
3848+
dim: Dims = None,
3849+
*,
3850+
axis: int | Sequence[int] | None = None,
3851+
keep_attrs: bool | None = None,
3852+
keepdims: bool = False,
3853+
shortcut: bool = True,
3854+
**kwargs: Any,
3855+
) -> Dataset:
3856+
raise NotImplementedError()
3857+
38323858
def reduce(
38333859
self,
38343860
func: Callable[..., Any],
@@ -5112,21 +5138,21 @@ def median(
51125138
51135139
>>> ds.resample(time="3M").median()
51145140
<xarray.Dataset>
5115-
Dimensions: (__resample_dim__: 3)
5141+
Dimensions: (time: 3)
51165142
Coordinates:
5117-
* __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0...
5143+
* time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31
51185144
Data variables:
5119-
da (__resample_dim__) float64 1.0 2.0 2.0
5145+
da (time) float64 1.0 2.0 2.0
51205146
51215147
Use ``skipna`` to control whether NaNs are ignored.
51225148
51235149
>>> ds.resample(time="3M").median(skipna=False)
51245150
<xarray.Dataset>
5125-
Dimensions: (__resample_dim__: 3)
5151+
Dimensions: (time: 3)
51265152
Coordinates:
5127-
* __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0...
5153+
* time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31
51285154
Data variables:
5129-
da (__resample_dim__) float64 1.0 2.0 nan
5155+
da (time) float64 1.0 2.0 nan
51305156
"""
51315157
return self._reduce_without_squeeze_warn(
51325158
duck_array_ops.median,
@@ -5343,6 +5369,19 @@ def cumprod(
53435369
class DataArrayGroupByAggregations:
53445370
_obj: DataArray
53455371

5372+
def _reduce_without_squeeze_warn(
5373+
self,
5374+
func: Callable[..., Any],
5375+
dim: Dims = None,
5376+
*,
5377+
axis: int | Sequence[int] | None = None,
5378+
keep_attrs: bool | None = None,
5379+
keepdims: bool = False,
5380+
shortcut: bool = True,
5381+
**kwargs: Any,
5382+
) -> DataArray:
5383+
raise NotImplementedError()
5384+
53465385
def reduce(
53475386
self,
53485387
func: Callable[..., Any],
@@ -6749,6 +6788,19 @@ def cumprod(
67496788
class DataArrayResampleAggregations:
67506789
_obj: DataArray
67516790

6791+
def _reduce_without_squeeze_warn(
6792+
self,
6793+
func: Callable[..., Any],
6794+
dim: Dims = None,
6795+
*,
6796+
axis: int | Sequence[int] | None = None,
6797+
keep_attrs: bool | None = None,
6798+
keepdims: bool = False,
6799+
shortcut: bool = True,
6800+
**kwargs: Any,
6801+
) -> DataArray:
6802+
raise NotImplementedError()
6803+
67526804
def reduce(
67536805
self,
67546806
func: Callable[..., Any],
@@ -7936,18 +7988,18 @@ def median(
79367988
labels (time) <U1 'a' 'b' 'c' 'c' 'b' 'a'
79377989
79387990
>>> da.resample(time="3M").median()
7939-
<xarray.DataArray (__resample_dim__: 3)>
7991+
<xarray.DataArray (time: 3)>
79407992
array([1., 2., 2.])
79417993
Coordinates:
7942-
* __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0...
7994+
* time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31
79437995
79447996
Use ``skipna`` to control whether NaNs are ignored.
79457997
79467998
>>> da.resample(time="3M").median(skipna=False)
7947-
<xarray.DataArray (__resample_dim__: 3)>
7999+
<xarray.DataArray (time: 3)>
79488000
array([ 1., 2., nan])
79498001
Coordinates:
7950-
* __resample_dim__ (__resample_dim__) datetime64[ns] 2001-01-31 ... 2001-0...
8002+
* time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31
79518003
"""
79528004
return self._reduce_without_squeeze_warn(
79538005
duck_array_ops.median,
@@ -8034,17 +8086,17 @@ def cumsum(
80348086
<xarray.DataArray (time: 6)>
80358087
array([1., 2., 5., 5., 2., 2.])
80368088
Coordinates:
8037-
* time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30
80388089
labels (time) <U1 'a' 'b' 'c' 'c' 'b' 'a'
8090+
Dimensions without coordinates: time
80398091
80408092
Use ``skipna`` to control whether NaNs are ignored.
80418093
80428094
>>> da.resample(time="3M").cumsum(skipna=False)
80438095
<xarray.DataArray (time: 6)>
80448096
array([ 1., 2., 5., 5., 2., nan])
80458097
Coordinates:
8046-
* time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30
80478098
labels (time) <U1 'a' 'b' 'c' 'c' 'b' 'a'
8099+
Dimensions without coordinates: time
80488100
"""
80498101
return self._reduce_without_squeeze_warn(
80508102
duck_array_ops.cumsum,
@@ -8131,17 +8183,17 @@ def cumprod(
81318183
<xarray.DataArray (time: 6)>
81328184
array([1., 2., 6., 0., 2., 2.])
81338185
Coordinates:
8134-
* time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30
81358186
labels (time) <U1 'a' 'b' 'c' 'c' 'b' 'a'
8187+
Dimensions without coordinates: time
81368188
81378189
Use ``skipna`` to control whether NaNs are ignored.
81388190
81398191
>>> da.resample(time="3M").cumprod(skipna=False)
81408192
<xarray.DataArray (time: 6)>
81418193
array([ 1., 2., 6., 0., 2., nan])
81428194
Coordinates:
8143-
* time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30
81448195
labels (time) <U1 'a' 'b' 'c' 'c' 'b' 'a'
8196+
Dimensions without coordinates: time
81458197
"""
81468198
return self._reduce_without_squeeze_warn(
81478199
duck_array_ops.cumprod,

xarray/util/generate_aggregations.py

+26
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ def reduce(
8989
class {obj}{cls}Aggregations:
9090
_obj: {obj}
9191
92+
def _reduce_without_squeeze_warn(
93+
self,
94+
func: Callable[..., Any],
95+
dim: Dims = None,
96+
*,
97+
axis: int | Sequence[int] | None = None,
98+
keep_attrs: bool | None = None,
99+
keepdims: bool = False,
100+
shortcut: bool = True,
101+
**kwargs: Any,
102+
) -> {obj}:
103+
raise NotImplementedError()
104+
92105
def reduce(
93106
self,
94107
func: Callable[..., Any],
@@ -113,6 +126,19 @@ def _flox_reduce(
113126
class {obj}{cls}Aggregations:
114127
_obj: {obj}
115128
129+
def _reduce_without_squeeze_warn(
130+
self,
131+
func: Callable[..., Any],
132+
dim: Dims = None,
133+
*,
134+
axis: int | Sequence[int] | None = None,
135+
keep_attrs: bool | None = None,
136+
keepdims: bool = False,
137+
shortcut: bool = True,
138+
**kwargs: Any,
139+
) -> {obj}:
140+
raise NotImplementedError()
141+
116142
def reduce(
117143
self,
118144
func: Callable[..., Any],

0 commit comments

Comments
 (0)