Skip to content

Commit

Permalink
BUG: Fixes GH3215 (#3220)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aidanheerdegen authored and shoyer committed Aug 28, 2019
1 parent 8969b5a commit aaeea62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 20 additions & 0 deletions xarray/tests/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit aaeea62

Please sign in to comment.