Skip to content

Commit

Permalink
Make sure that we don't rechunk the entire variable to one chunk
Browse files Browse the repository at this point in the history
by reducing over all dimensions. Dask raises an error when axis=None
but not when axis=range(a.ndim).
  • Loading branch information
dcherian committed Dec 17, 2019
1 parent 54bea40 commit 285258d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xarray/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def nanmean(a, axis=None, dtype=None, out=None):


def nanmedian(a, axis=None, out=None):
# The dask algorithm works by rechunking to one chunk along axis
# Make sure we trigger the dask error when passing all dimensions
# so that we don't rechunk the entire array to one chunk and
# possibly blow memory
if axis is not None and len(axis) == a.ndim:
axis = None
return _dask_or_eager_func(
"nanmedian", dask_module=dask_array_compat, eager_module=nputils
)(a, axis=axis)
Expand Down
2 changes: 2 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def test_reduce(self):
self.assertLazyAndAllClose((u < 1).all("x"), (v < 1).all("x"))
with raises_regex(NotImplementedError, "only works along an axis"):
v.median()
with raises_regex(NotImplementedError, "only works along an axis"):
v.median(v.dims)
with raise_if_dask_computes():
v.reduce(duck_array_ops.mean)

Expand Down

0 comments on commit 285258d

Please sign in to comment.