Skip to content

Commit

Permalink
More explicit check for dtype roundtripping in backends (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer authored Mar 21, 2017
1 parent 31b46dc commit 65555b8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,24 @@ def test_write_store(self):
actual = xr.decode_cf(store)
self.assertDatasetAllClose(expected, actual)

def check_dtypes_roundtripped(self, expected, actual):
for k in expected:
expected_dtype = expected.variables[k].dtype
if (isinstance(self, Only32BitTypes) and
expected_dtype == 'int64'):
# downcast
expected_dtype = np.dtype('int32')
actual_dtype = actual.variables[k].dtype
# TODO: check expected behavior for string dtypes more carefully
string_kinds = {'O', 'S', 'U'}
assert (expected_dtype == actual_dtype or
(expected_dtype.kind in string_kinds and
actual_dtype.kind in string_kinds))

def test_roundtrip_test_data(self):
expected = create_test_data()
with self.roundtrip(expected) as actual:
self.check_dtypes_roundtripped(expected, actual)
self.assertDatasetAllClose(expected, actual)

def test_load(self):
Expand Down

0 comments on commit 65555b8

Please sign in to comment.