8000 Fix failed tests · pydata/xarray@7418924 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7418924

Browse files
committed
Fix failed tests
1 parent e723941 commit 7418924

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

xarray/conventions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def _var_as_tuple(var):
8080

8181
def maybe_encode_nonstring_dtype(var, name=None):
8282
if ('dtype' in var.encoding and
83-
var.encoding['dtype'] not in {'S1', str}):
83+
var.encoding['dtype'] != 'S1' and
84+
var.encoding['dtype'] is not str):
8485
dims, data, attrs, encoding = _var_as_tuple(var)
8586
dtype = np.dtype(encoding.pop('dtype'))
8687
if dtype != var.dtype:

xarray/tests/test_backends.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def test_encoding_kwarg_dates(self):
756756
self.assertEqual(actual.t.encoding['units'], units)
757757
assert_identical(actual, ds)
758758

759-
def test_encoding_kwarg_string(self):
759+
def test_encoding_kwarg_fixed_width_string(self):
760760
# regression test for GH2149
761761
for strings in [
762762
[b'foo', b'bar', b'baz'],
@@ -948,17 +948,17 @@ def test_write_groups(self):
948948
with open_dataset(tmp_file, group='data/2') as actual2:
949949
assert_identical(data2, actual2)
950950

951-
@pytest.mark.parametrize('input_strings', [
952-
[b'foo', b'bar', b'baz'],
953-
[u'foo', u'bar', u'baz'],
954-
])
955-
def test_encoding_kwarg_vlen_string(self, input_strings):
956-
original = Dataset({'x': input_strings})
957-
expected = Dataset({'x': [u'foo', u'bar', u'baz']})
958-
kwargs = dict(encoding={'x': {'dtype': str}})
959-
with self.roundtrip(original, save_kwargs=kwargs) as actual:
960-
assert actual['x'].encoding['dtype'] is str
961-
assert_identical(actual, expected)
951+
def test_encoding_kwarg_vlen_string(self):
952+
for input_strings in [
953+
[b'foo', b'bar', b'baz'],
954+
[u'foo', u'bar', u'baz'],
955+
]:
956+
original = Dataset({'x': input_strings})
957+
expected = Dataset({'x': [u'foo', u'bar', u'baz']})
958+
kwargs = dict(encoding={'x': {'dtype': str}})
959+
with self.roundtrip(original, save_kwargs=kwargs) as actual:
960+
assert actual['x'].encoding['dtype'] is str
961+
assert_identical(actual, expected)
962962

963963
def test_roundtrip_string_with_fill_value_vlen(self):
964964
values = np.array([u'ab', u'cdef', np.nan], dtype=object)
@@ -1445,7 +1445,7 @@ def test_group(self):
14451445
open_kwargs={'group': group}) as actual:
14461446
assert_identical(original, actual)
14471447

1448-
def test_encoding_kwarg_string(self):
1448+
def test_encoding_kwarg_fixed_width_string(self):
14491449
# not relevant for zarr, since we don't use EncodedStringCoder
14501450
pass
14511451

xarray/tests/test_conventions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,5 @@ def test_invalid_dataarray_names_raise(self):
275275
def test_encoding_kwarg(self):
276276
pass
277277

278-
def test_encoding_kwarg_string(self):
278+
def test_encoding_kwarg_fixed_width_string(self):
279279
pass

0 commit comments

Comments
 (0)
0