Fix tests on big-endian systems

Also, remove a redundant skip, as the listed test is skipped by upstream
already.
This commit is contained in:
Elliott Sales de Andrade
2024-08-19 01:35:57 -04:00
parent 4a8ca0c05d
commit b4a8abb2fc
4 changed files with 92 additions and 14 deletions
@@ -1,7 +1,7 @@
From f2b1952202db32b956566648dec4cfd302f54316 Mon Sep 17 00:00:00 2001
From 955e5695e632ec368e25ca2d4afdb7d669a17bfe Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Fri, 15 Mar 2019 22:48:25 -0400
Subject: [PATCH 1/2] DOC: Skip examples using unpackaged dependencies.
Subject: [PATCH 1/3] DOC: Skip examples using unpackaged dependencies.
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
@@ -9,10 +9,10 @@ Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 file changed, 2 insertions(+)
diff --git a/doc/user-guide/io.rst b/doc/user-guide/io.rst
index dc495b9f..e03080a1 100644
index 85c47334..2a03cb4e 100644
--- a/doc/user-guide/io.rst
+++ b/doc/user-guide/io.rst
@@ -921,6 +921,7 @@ installed, xarray can convert a ``DataArray`` into a ``Cube`` using
@@ -1072,6 +1072,7 @@ installed, xarray can convert a ``DataArray`` into a ``Cube`` using
:py:meth:`DataArray.to_iris`:
.. ipython:: python
@@ -20,7 +20,7 @@ index dc495b9f..e03080a1 100644
da = xr.DataArray(
np.random.rand(4, 5),
@@ -935,6 +936,7 @@ Conversely, we can create a new ``DataArray`` object from a ``Cube`` using
@@ -1086,6 +1087,7 @@ Conversely, we can create a new ``DataArray`` object from a ``Cube`` using
:py:meth:`DataArray.from_iris`:
.. ipython:: python
@@ -29,5 +29,5 @@ index dc495b9f..e03080a1 100644
da_cube = xr.DataArray.from_iris(cube)
da_cube
--
2.39.2
2.45.2
@@ -1,7 +1,7 @@
From f85d7fd7257f3c109987022e35f81da24a32bdbf Mon Sep 17 00:00:00 2001
From 1b0312ce5e355ba1e9ecb6838817a9ba1154bf8c Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Sat, 16 Mar 2019 02:59:15 -0400
Subject: [PATCH 2/2] DOC: Don't print out conda/pip environment.
Subject: [PATCH 2/3] DOC: Don't print out conda/pip environment.
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
@@ -9,7 +9,7 @@ Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 file changed, 8 deletions(-)
diff --git a/doc/conf.py b/doc/conf.py
index eb861004..faed9753 100644
index 4f1fc675..3415bcd0 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -16,7 +16,6 @@ import datetime
@@ -35,5 +35,5 @@ index eb861004..faed9753 100644
with suppress(ImportError):
--
2.39.2
2.45.2
@@ -0,0 +1,78 @@
From b2594026663f5d61b5a3e01e790c2a1c8e3e72a8 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Mon, 19 Aug 2024 01:16:05 -0400
Subject: [PATCH 3/3] Fix tests on big-endian systems
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.
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
xarray/tests/test_backends.py | 6 +++---
xarray/tests/test_coding_times.py | 4 ++--
xarray/tests/test_dask.py | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py
index 4fa87364..0ae3062c 100644
--- a/xarray/tests/test_backends.py
+++ b/xarray/tests/test_backends.py
@@ -872,7 +872,7 @@ class CFEncodedBase(DatasetIOBase):
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",
@@ -1430,8 +1430,8 @@ class NetCDF4Base(NetCDFBase):
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"])
diff --git a/xarray/tests/test_coding_times.py b/xarray/tests/test_coding_times.py
index ef478af8..e1bf2edf 100644
--- a/xarray/tests/test_coding_times.py
+++ b/xarray/tests/test_coding_times.py
@@ -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 (
@@ -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"
diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py
index 20491eca..7750cdd4 100644
--- a/xarray/tests/test_dask.py
+++ b/xarray/tests/test_dask.py
@@ -1378,7 +1378,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
--
2.45.2
+4 -4
View File
@@ -14,8 +14,10 @@ Source0: %pypi_source %{srcname}
# Data for examples only.
Source1: https://github.com/pydata/xarray-data/archive/%{data_commit}/xarray-data-%{data_commit}.tar.gz
# All Fedora specific.
Patch0001: 0001-DOC-Skip-examples-using-unpackaged-dependencies.patch
Patch0002: 0002-DOC-Don-t-print-out-conda-pip-environment.patch
Patch: 0001-DOC-Skip-examples-using-unpackaged-dependencies.patch
Patch: 0002-DOC-Don-t-print-out-conda-pip-environment.patch
# https://github.com/pydata/xarray/pull/9380
Patch: 0003-Fix-tests-on-big-endian-systems.patch
BuildArch: noarch
@@ -113,8 +115,6 @@ rm -rf xarray
pytest_args=(
-n auto
-m "not network"
# https://github.com/pydata/xarray/issues/7513
-k 'not test_open_mfdataset_manyfiles'
# this test somehow crashes python interpreter entirely, was xfail upstream till recently
-k 'not test_save_mfdataset_compute_false_roundtrip'
)