Skip to content

Commit aaeea62

Browse files
aidanheerdegenshoyer
authored andcommitted
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
1 parent 8969b5a commit aaeea62

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

xarray/core/formatting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def last_item(array):
9696
return []
9797

9898
indexer = (slice(-1, None),) * array.ndim
99-
return np.ravel(array[indexer]).tolist()
99+
return np.ravel(np.asarray(array[indexer])).tolist()
100100

101101

102102
def format_timestamp(t):

xarray/tests/test_conventions.py

+20
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ def test_decode_cf_with_dask(self):
278278
)
279279
assert_identical(decoded, conventions.decode_cf(original).compute())
280280

281+
@requires_dask
282+
def test_decode_dask_times(self):
283+
original = Dataset.from_dict(
284+
{
285+
"coords": {},
286+
"dims": {"time": 5},
287+
"data_vars": {
288+
"average_T1": {
289+
"dims": ("time",),
290+
"attrs": {"units": "days since 1958-01-01 00:00:00"},
291+
"data": [87659.0, 88024.0, 88389.0, 88754.0, 89119.0],
292+
}
293+
},
294+
}
295+
)
296+
assert_identical(
297+
conventions.decode_cf(original.chunk()),
298+
conventions.decode_cf(original).chunk(),
299+
)
300+
281301

282302
class CFEncodedInMemoryStore(WritableCFDataStore, InMemoryDataStore):
283303
def encode_variable(self, var):

0 commit comments

Comments
 (0)