Skip to content

Commit 602d043

Browse files
committed
Adjust after pydata#8183
1 parent 374ac99 commit 602d043

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

xarray/core/rolling_exp.py

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -131,42 +131,15 @@ def mean(self, keep_attrs: bool | None = None) -> T_DataWithCoords:
131131

132132
dim_order = self.obj.dims
133133

134-
from xarray.core.dataset import Dataset
135-
136-
if isinstance(self.obj, Dataset):
137-
new_ds = self.obj.copy()
138-
if not keep_attrs:
139-
new_ds.attrs = {}
140-
for name, var in self.obj.variables.items():
141-
if self.dim in self.obj[name].dims:
142-
new_ds[name] = apply_ufunc(
143-
move_exp_nanmean,
144-
var,
145-
input_core_dims=[[self.dim]],
146-
kwargs=dict(alpha=self.alpha, axis=-1),
147-
output_core_dims=[[self.dim]],
148-
# I'm not sure whether this line should be here (can look later,
149-
# docs aren't _that_ clear vs. `input_core_dims`, or I'm being
150-
# slow at understanding them.)
151-
exclude_dims={self.dim},
152-
keep_attrs=keep_attrs,
153-
)
154-
# Currently we test for attrs being removed on all arrays, even those
155-
# without the dim, not sure if we should be doing this or not (we can
156-
# indent a line and then only remove attrs on arrays we compute on)
157-
if not keep_attrs:
158-
new_ds[name].attrs = {}
159-
return new_ds.transpose(*dim_order)
160-
else:
161-
return apply_ufunc(
162-
move_exp_nanmean,
163-
self.obj,
164-
input_core_dims=[[self.dim]],
165-
kwargs=dict(alpha=self.alpha, axis=-1),
166-
output_core_dims=[[self.dim]],
167-
exclude_dims={self.dim},
168-
keep_attrs=keep_attrs,
169-
).transpose(*dim_order)
134+
return apply_ufunc(
135+
move_exp_nanmean,
136+
self.obj,
137+
input_core_dims=[[self.dim]],
138+
kwargs=dict(alpha=self.alpha, axis=-1),
139+
output_core_dims=[[self.dim]],
140+
exclude_dims={self.dim},
141+
keep_attrs=keep_attrs,
142+
).transpose(*dim_order)
170143

171144
def sum(self, keep_attrs: bool | None = None) -> T_DataWithCoords:
172145
"""

0 commit comments

Comments
 (0)