Skip to content

Commit

Permalink
Fix tests on big-endian systems
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
QuLogic committed Aug 19, 2024
1 parent da9e7ec commit 8c62e46
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ def test_roundtrip_empty_vlen_string_array(self) -> None:
if actual["a"].dtype.metadata is not None:
assert check_vlen_dtype(actual["a"].dtype) is str
else:
assert actual["a"].dtype == np.dtype("<U1")
assert actual["a"].dtype == np.dtype("=U1")

@pytest.mark.parametrize(
"decoded_fn, encoded_fn",
Expand Down Expand Up @@ -1430,8 +1430,8 @@ def test_encoding_kwarg_vlen_string(
expected = Dataset({"x": expected_string})
kwargs = dict(encoding={"x": {"dtype": str}})
with self.roundtrip(original, save_kwargs=kwargs) as actual:
assert actual["x"].encoding["dtype"] == "<U3"
assert actual["x"].dtype == "<U3"
assert actual["x"].encoding["dtype"] == "=U3"
assert actual["x"].dtype == "=U3"
assert_identical(actual, expected)

@pytest.mark.parametrize("fill_value", ["XXX", "", "bár"])
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ def test_roundtrip_datetime64_nanosecond_precision(
encoding = {}

var = Variable(["time"], times, encoding=encoding)
assert var.dtype == np.dtype("<M8[ns]")
assert var.dtype == np.dtype("=M8[ns]")

encoded_var = conventions.encode_cf_variable(var)
assert (
Expand All @@ -1264,7 +1264,7 @@ def test_roundtrip_datetime64_nanosecond_precision(
assert encoded_var.data.dtype == dtype

decoded_var = conventions.decode_cf_variable("foo", encoded_var)
assert decoded_var.dtype == np.dtype("<M8[ns]")
assert decoded_var.dtype == np.dtype("=M8[ns]")
assert (
decoded_var.encoding["units"]
== f"{_numpy_to_netcdf_timeunit(timeunit)} since 1970-01-01 00:00:00"
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ def test_map_blocks_roundtrip_string_index():
ds = xr.Dataset(
{"data": (["label"], [1, 2, 3])}, coords={"label": ["foo", "bar", "baz"]}
).chunk(label=1)
assert ds.label.dtype == np.dtype("<U3")
assert ds.label.dtype == np.dtype("=U3")

mapped = ds.map_blocks(lambda x: x, template=ds)
assert mapped.label.dtype == ds.label.dtype
Expand Down

0 comments on commit 8c62e46

Please sign in to comment.