Skip to content

Commit ec6e160

Browse files
Joe Hammanshoyer
Joe Hamman
authored andcommitted
Fix/dask isnull (#1939)
* fix isnull for dask arrays and add test to test_duck_array_ops.py * minor cleanup / proper test skipping in test_duck_array_ops.py * whatsnew * Fixing style errors. * flake8
1 parent f053567 commit ec6e160

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

doc/whats-new.rst

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ Bug fixes
167167
match pandas (:issue:`1847`). A combination of strings/numbers or
168168
unicode/bytes now promote to object dtype, instead of strings or unicode.
169169
By `Stephan Hoyer <https://github.com/shoyer>`_.
170+
- Fixed bug where :py:meth:`~xarray.DataArray.isnull` was loading data
171+
stored as dask arrays (:issue:`1937`).
172+
By `Joe Hamman <https://github.com/jhamman>`_.
170173

171174
.. _whats-new.0.10.0:
172175

xarray/core/ops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import operator
1313

1414
import numpy as np
15-
import pandas as pd
1615

1716
from . import dtypes
1817
from . import duck_array_ops
@@ -320,7 +319,8 @@ def inject_all_ops_and_reduce_methods(cls, priority=50, array_only=True):
320319
setattr(cls, name, cls._unary_op(_method_wrapper(name)))
321320

322321
for name in PANDAS_UNARY_FUNCTIONS:
323-
f = _func_slash_method_wrapper(getattr(pd, name), name=name)
322+
f = _func_slash_method_wrapper(
323+
getattr(duck_array_ops, name), name=name)
324324
setattr(cls, name, cls._unary_op(f))
325325

326326
f = _func_slash_method_wrapper(duck_array_ops.around, name='round')

xarray/tests/test_duck_array_ops.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
from xarray.core.duck_array_ops import (
1010
first, last, count, mean, array_notnull_equiv, where, stack, concatenate
1111
)
12+
from xarray.core.pycompat import dask_array_type
1213
from xarray import DataArray
13-
from xarray.testing import assert_allclose
14+
from xarray.testing import assert_allclose, assert_equal
1415
from xarray import concat
1516

16-
from . import TestCase, raises_regex, has_dask
17+
from . import TestCase, raises_regex, has_dask, requires_dask
1718

1819

1920
class TestOps(TestCase):
@@ -194,23 +195,19 @@ def series_reduce(da, func, dim, **kwargs):
194195
def test_reduce(dim_num, dtype, dask, func, skipna, aggdim):
195196

196197
if aggdim == 'y' and dim_num < 2:
197-
return
198+
pytest.skip('dim not in this test')
198199

199200
if dtype == np.bool_ and func == 'mean':
200-
return # numpy does not support this
201+
pytest.skip('numpy does not support this')
201202

202203
if dask and not has_dask:
203-
return
204+
pytest.skip('requires dask')
204205

205206
rtol = 1e-04 if dtype == np.float32 else 1e-05
206207

207208
da = construct_dataarray(dim_num, dtype, contains_nan=True, dask=dask)
208209
axis = None if aggdim is None else da.get_axis_num(aggdim)
209210

210-
if dask and not skipna and func in ['var', 'std'] and dtype == np.bool_:
211-
# TODO this might be dask's bug
212-
return
213-
214211
if (LooseVersion(np.__version__) >= LooseVersion('1.13.0') and
215212
da.dtype.kind == 'O' and skipna):
216213
# Numpy < 1.13 does not handle object-type array.
@@ -269,19 +266,17 @@ def test_argmin_max(dim_num, dtype, contains_nan, dask, func, skipna, aggdim):
269266
# just make sure da[da.argmin()] == da.min()
270267

271268
if aggdim == 'y' and dim_num < 2:
272-
return
269+
pytest.skip('dim not in this test')
273270

274271
if dask and not has_dask:
275-
return
272+
pytest.skip('requires dask')
276273

277274
if contains_nan:
278275
if not skipna:
279-
# numpy's argmin (not nanargmin) does not handle object-dtype
280-
return
276+
pytest.skip("numpy's argmin (not nanargmin) does not handle "
277+
"object-dtype")
281278
if skipna and np.dtype(dtype).kind in 'iufc':
282-
# numpy's nanargmin raises ValueError for all nan axis
283-
return
284-
279+
pytest.skip("numpy's nanargmin raises ValueError for all nan axis")
285280
da = construct_dataarray(dim_num, dtype, contains_nan=contains_nan,
286281
dask=dask)
287282

@@ -302,3 +297,10 @@ def test_argmin_max_error():
302297
da = construct_dataarray(2, np.bool_, contains_nan=True, dask=False)
303298
with pytest.raises(ValueError):
304299
da.argmin(dim='y')
300+
301+
302+
@requires_dask
303+
def test_isnull_with_dask():
304+
da = construct_dataarray(2, np.float32, contains_nan=True, dask=True)
305+
assert isinstance(da.isnull().data, dask_array_type)
306+
assert_equal(da.isnull().load(), da.load().isnull())

0 commit comments

Comments
 (0)