Skip to content

raise TypeError in Variable.quantile if data is a dask array #1529

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 3 commits into from
Aug 28, 2017
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
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Bug fixes
``rtol`` arguments when called on ``DataArray`` objects.
By `Stephan Hoyer <https://github.com/shoyer>`_.

- Xarray ``quantile`` methods now properly raise a ``TypeError`` when applied to
objects with data stored as ``dask`` arrays (:issue:`1529`).
By `Joe Hamman <https://github.com/jhamman>`_.

.. _whats-new.0.9.6:

v0.9.6 (8 June 2017)
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,9 +1114,9 @@ def quantile(self, q, dim=None, interpolation='linear'):
"""

if isinstance(self.data, dask_array_type):
TypeError("quantile does not work for arrays stored as dask "
"arrays. Load the data via .compute() or .load() prior "
"to calling this method.")
raise TypeError("quantile does not work for arrays stored as dask "
"arrays. Load the data via .compute() or .load() "
"prior to calling this method.")
if LooseVersion(np.__version__) < LooseVersion('1.10.0'):
raise NotImplementedError(
'quantile requres numpy version 1.10.0 or later')
Expand Down
10 changes: 9 additions & 1 deletion xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,14 @@ def test_quantile(self):
axis=axis)
np.testing.assert_allclose(actual.values, expected)

@requires_dask
def test_quantile_dask_raises(self):
# regression for GH1524
v = Variable(['x', 'y'], self.d).chunk(2)

with self.assertRaisesRegexp(TypeError, 'arrays stored as dask'):
v.quantile(0.5, dim='x')

def test_big_endian_reduce(self):
# regression test for GH489
data = np.ones(5, dtype='>f4')
Expand Down Expand Up @@ -1243,7 +1251,7 @@ def test_full_like(self):

@requires_dask
def test_full_like_dask(self):
orig = Variable(dims=('x', 'y'), data=[[1.5 ,2.0], [3.1, 4.3]],
orig = Variable(dims=('x', 'y'), data=[[1.5, 2.0], [3.1, 4.3]],
attrs={'foo': 'bar'}).chunk(((1, 1), (2,)))

def check(actual, expect_dtype, expect_values):
Expand Down