From aaeea6250b89e3605ee1d1a160ad50d6ed657c7e Mon Sep 17 00:00:00 2001 From: Aidan Heerdegen Date: Wed, 28 Aug 2019 16:45:34 +1000 Subject: [PATCH] BUG: Fixes GH3215 (#3220) * BUG: Fixes GH3215 Explicit cast to numpy array to avoid np.ravel calling out to dask * Added test * Added assertion to test * Removed assertion. Didn't work * PEP8 and flake fixes * Ran black * Implement suggested fixes * Added assert test * Added valid assert_identical test * add requires_dask --- xarray/core/formatting.py | 2 +- xarray/tests/test_conventions.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 51664fb3e32..c6b2537c958 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -96,7 +96,7 @@ def last_item(array): return [] indexer = (slice(-1, None),) * array.ndim - return np.ravel(array[indexer]).tolist() + return np.ravel(np.asarray(array[indexer])).tolist() def format_timestamp(t): diff --git a/xarray/tests/test_conventions.py b/xarray/tests/test_conventions.py index 36c1d845f8e..5d80abb4661 100644 --- a/xarray/tests/test_conventions.py +++ b/xarray/tests/test_conventions.py @@ -278,6 +278,26 @@ def test_decode_cf_with_dask(self): ) assert_identical(decoded, conventions.decode_cf(original).compute()) + @requires_dask + def test_decode_dask_times(self): + original = Dataset.from_dict( + { + "coords": {}, + "dims": {"time": 5}, + "data_vars": { + "average_T1": { + "dims": ("time",), + "attrs": {"units": "days since 1958-01-01 00:00:00"}, + "data": [87659.0, 88024.0, 88389.0, 88754.0, 89119.0], + } + }, + } + ) + assert_identical( + conventions.decode_cf(original.chunk()), + conventions.decode_cf(original).chunk(), + ) + class CFEncodedInMemoryStore(WritableCFDataStore, InMemoryDataStore): def encode_variable(self, var):