Skip to content

Fix/dask isnull #1939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ Bug fixes
match pandas (:issue:`1847`). A combination of strings/numbers or
unicode/bytes now promote to object dtype, instead of strings or unicode.
By `Stephan Hoyer <https://github.com/shoyer>`_.
- Fixed bug where :py:meth:`~xarray.DataArray.isnull` was loading data
stored as dask arrays (:issue:`1937`).
By `Joe Hamman <https://github.com/jhamman>`_.

.. _whats-new.0.10.0:

Expand Down
4 changes: 2 additions & 2 deletions xarray/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import operator

import numpy as np
import pandas as pd

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

for name in PANDAS_UNARY_FUNCTIONS:
f = _func_slash_method_wrapper(getattr(pd, name), name=name)
f = _func_slash_method_wrapper(
getattr(duck_array_ops, name), name=name)
setattr(cls, name, cls._unary_op(f))

f = _func_slash_method_wrapper(duck_array_ops.around, name='round')
Expand Down
34 changes: 18 additions & 16 deletions xarray/tests/test_duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
from xarray.core.duck_array_ops import (
first, last, count, mean, array_notnull_equiv, where, stack, concatenate
)
from xarray.core.pycompat import dask_array_type
from xarray import DataArray
from xarray.testing import assert_allclose
from xarray.testing import assert_allclose, assert_equal
from xarray import concat

from . import TestCase, raises_regex, has_dask
from . import TestCase, raises_regex, has_dask, requires_dask


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

if aggdim == 'y' and dim_num < 2:
return
pytest.skip('dim not in this test')

if dtype == np.bool_ and func == 'mean':
return # numpy does not support this
pytest.skip('numpy does not support this')

if dask and not has_dask:
return
pytest.skip('requires dask')

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

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

if dask and not skipna and func in ['var', 'std'] and dtype == np.bool_:
# TODO this might be dask's bug
return

if (LooseVersion(np.__version__) >= LooseVersion('1.13.0') and
da.dtype.kind == 'O' and skipna):
# Numpy < 1.13 does not handle object-type array.
Expand Down Expand Up @@ -269,19 +266,17 @@ def test_argmin_max(dim_num, dtype, contains_nan, dask, func, skipna, aggdim):
# just make sure da[da.argmin()] == da.min()

if aggdim == 'y' and dim_num < 2:
return
pytest.skip('dim not in this test')

if dask and not has_dask:
return
pytest.skip('requires dask')

if contains_nan:
if not skipna:
# numpy's argmin (not nanargmin) does not handle object-dtype
return
pytest.skip("numpy's argmin (not nanargmin) does not handle "
"object-dtype")
if skipna and np.dtype(dtype).kind in 'iufc':
# numpy's nanargmin raises ValueError for all nan axis
return

pytest.skip("numpy's nanargmin raises ValueError for all nan axis")
da = construct_dataarray(dim_num, dtype, contains_nan=contains_nan,
dask=dask)

Expand All @@ -302,3 +297,10 @@ def test_argmin_max_error():
da = construct_dataarray(2, np.bool_, contains_nan=True, dask=False)
with pytest.raises(ValueError):
da.argmin(dim='y')


@requires_dask
def test_isnull_with_dask():
da = construct_dataarray(2, np.float32, contains_nan=True, dask=True)
assert isinstance(da.isnull().data, dask_array_type)
assert_equal(da.isnull().load(), da.load().isnull())