Skip to content

Commit ca2e9d6

Browse files
authored
Fix tests on big-endian systems (#9380)
There is nothing in the data created in these tests that requires them to be little endian, so the dtype comparison should be for native byte order.
1 parent da9e7ec commit ca2e9d6

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

xarray/tests/test_backends.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ def test_roundtrip_empty_vlen_string_array(self) -> None:
872872
if actual["a"].dtype.metadata is not None:
873873
assert check_vlen_dtype(actual["a"].dtype) is str
874874
else:
875-
assert actual["a"].dtype == np.dtype("<U1")
875+
assert actual["a"].dtype == np.dtype("=U1")
876876

877877
@pytest.mark.parametrize(
878878
"decoded_fn, encoded_fn",
@@ -1430,8 +1430,8 @@ def test_encoding_kwarg_vlen_string(
14301430
expected = Dataset({"x": expected_string})
14311431
kwargs = dict(encoding={"x": {"dtype": str}})
14321432
with self.roundtrip(original, save_kwargs=kwargs) as actual:
1433-
assert actual["x"].encoding["dtype"] == "<U3"
1434-
assert actual["x"].dtype == "<U3"
1433+
assert actual["x"].encoding["dtype"] == "=U3"
1434+
assert actual["x"].dtype == "=U3"
14351435
assert_identical(actual, expected)
14361436

14371437
@pytest.mark.parametrize("fill_value", ["XXX", "", "bár"])

xarray/tests/test_coding_times.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def test_roundtrip_datetime64_nanosecond_precision(
12531253
encoding = {}
12541254

12551255
var = Variable(["time"], times, encoding=encoding)
1256-
assert var.dtype == np.dtype("<M8[ns]")
1256+
assert var.dtype == np.dtype("=M8[ns]")
12571257

12581258
encoded_var = conventions.encode_cf_variable(var)
12591259
assert (
@@ -1264,7 +1264,7 @@ def test_roundtrip_datetime64_nanosecond_precision(
12641264
assert encoded_var.data.dtype == dtype
12651265

12661266
decoded_var = conventions.decode_cf_variable("foo", encoded_var)
1267-
assert decoded_var.dtype == np.dtype("<M8[ns]")
1267+
assert decoded_var.dtype == np.dtype("=M8[ns]")
12681268
assert (
12691269
decoded_var.encoding["units"]
12701270
== f"{_numpy_to_netcdf_timeunit(timeunit)} since 1970-01-01 00:00:00"

xarray/tests/test_dask.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ def test_map_blocks_roundtrip_string_index():
13811381
ds = xr.Dataset(
13821382
{"data": (["label"], [1, 2, 3])}, coords={"label": ["foo", "bar", "baz"]}
13831383
).chunk(label=1)
1384-
assert ds.label.dtype == np.dtype("<U3")
1384+
assert ds.label.dtype == np.dtype("=U3")
13851385

13861386
mapped = ds.map_blocks(lambda x: x, template=ds)
13871387
assert mapped.label.dtype == ds.label.dtype

0 commit comments

Comments
 (0)