diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 7d06a49d486..010f4856bb0 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -74,6 +74,10 @@ Bug fixes ``rtol`` arguments when called on ``DataArray`` objects. By `Stephan Hoyer `_. +- Xarray ``quantile`` methods now properly raise a ``TypeError`` when applied to + objects with data stored as ``dask`` arrays (:issue:`1529`). + By `Joe Hamman `_. + .. _whats-new.0.9.6: v0.9.6 (8 June 2017) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index b1a2b1add74..b02882bc2ac 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -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') diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index f5d207d0978..7b68783f611 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -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') @@ -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):