Skip to content

Commit 285258d

Browse files
committed
Make sure that we don't rechunk the entire variable to one chunk
by reducing over all dimensions. Dask raises an error when axis=None but not when axis=range(a.ndim).
1 parent 54bea40 commit 285258d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

xarray/core/nanops.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ def nanmean(a, axis=None, dtype=None, out=None):
143143

144144

145145
def nanmedian(a, axis=None, out=None):
146+
# The dask algorithm works by rechunking to one chunk along axis
147+
# Make sure we trigger the dask error when passing all dimensions
148+
# so that we don't rechunk the entire array to one chunk and
149+
# possibly blow memory
150+
if axis is not None and len(axis) == a.ndim:
151+
axis = None
146152
return _dask_or_eager_func(
147153
"nanmedian", dask_module=dask_array_compat, eager_module=nputils
148154
)(a, axis=axis)

xarray/tests/test_dask.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def test_reduce(self):
218218
self.assertLazyAndAllClose((u < 1).all("x"), (v < 1).all("x"))
219219
with raises_regex(NotImplementedError, "only works along an axis"):
220220
v.median()
221+
with raises_regex(NotImplementedError, "only works along an axis"):
222+
v.median(v.dims)
221223
with raise_if_dask_computes():
222224
v.reduce(duck_array_ops.mean)
223225

0 commit comments

Comments
 (0)