Fix additional architecture-specific bugs
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
From f41100ae4202dce5891854143ba3a31f4e2d5a6d Mon Sep 17 00:00:00 2001
|
||||
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
Date: Tue, 14 Jan 2025 02:46:39 -0500
|
||||
Subject: [PATCH 1/2] Fix test_doc_example on big-endian systems
|
||||
|
||||
... by using a fixed-endian input.
|
||||
|
||||
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
---
|
||||
xarray/tests/test_datatree.py | 8 ++++++--
|
||||
1 file changed, 6 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/xarray/tests/test_datatree.py b/xarray/tests/test_datatree.py
|
||||
index 7b295128..21870050 100644
|
||||
--- a/xarray/tests/test_datatree.py
|
||||
+++ b/xarray/tests/test_datatree.py
|
||||
@@ -1240,8 +1240,12 @@ class TestRepr:
|
||||
)
|
||||
def test_doc_example(self) -> None:
|
||||
# regression test for https://github.com/pydata/xarray/issues/9499
|
||||
- time = xr.DataArray(data=["2022-01", "2023-01"], dims="time")
|
||||
- stations = xr.DataArray(data=list("abcdef"), dims="station")
|
||||
+ time = xr.DataArray(
|
||||
+ data=np.array(["2022-01", "2023-01"], dtype="<U7"), dims="time"
|
||||
+ )
|
||||
+ stations = xr.DataArray(
|
||||
+ data=np.array(list("abcdef"), dtype="<U1"), dims="station"
|
||||
+ )
|
||||
lon = [-100, -80, -60]
|
||||
lat = [10, 20, 30]
|
||||
# Set up fake data
|
||||
--
|
||||
2.47.0
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
From e84321150e52a19e617efd7f8798d6859bd3c5e7 Mon Sep 17 00:00:00 2001
|
||||
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
Date: Sun, 19 Jan 2025 04:47:23 -0500
|
||||
Subject: [PATCH 2/2] Avoid unsafe casts from float to unsigned int
|
||||
|
||||
Fixes #9815
|
||||
|
||||
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
---
|
||||
xarray/coding/variables.py | 5 ++++-
|
||||
xarray/core/duck_array_ops.py | 10 ++++++++++
|
||||
2 files changed, 14 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py
|
||||
index 8154f044..355f3b0b 100644
|
||||
--- a/xarray/coding/variables.py
|
||||
+++ b/xarray/coding/variables.py
|
||||
@@ -426,7 +426,10 @@ class CFMaskCoder(VariableCoder):
|
||||
if fill_value is not None and has_unsigned:
|
||||
pop_to(encoding, attrs, "_Unsigned")
|
||||
# XXX: Is this actually needed? Doesn't the backend handle this?
|
||||
- data = duck_array_ops.astype(duck_array_ops.around(data), dtype)
|
||||
+ signed_dtype = np.dtype(f"i{dtype.itemsize}")
|
||||
+ data = duck_array_ops.view(
|
||||
+ duck_array_ops.astype(duck_array_ops.around(data), signed_dtype), dtype
|
||||
+ )
|
||||
attrs["_FillValue"] = fill_value
|
||||
|
||||
return Variable(dims, data, attrs, encoding, fastpath=True)
|
||||
diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py
|
||||
index 7e7333fd..be842b66 100644
|
||||
--- a/xarray/core/duck_array_ops.py
|
||||
+++ b/xarray/core/duck_array_ops.py
|
||||
@@ -236,6 +236,16 @@ def astype(data, dtype, **kwargs):
|
||||
return data.astype(dtype, **kwargs)
|
||||
|
||||
|
||||
+def view(data, *args, **kwargs):
|
||||
+ if hasattr(data, "__array_namespace__"):
|
||||
+ xp = get_array_namespace(data)
|
||||
+ if xp == np:
|
||||
+ # numpy currently doesn't have a view:
|
||||
+ return data.view(*args, **kwargs)
|
||||
+ return xp.view(data, *args, **kwargs)
|
||||
+ return data.view(*args, **kwargs)
|
||||
+
|
||||
+
|
||||
def asarray(data, xp=np, dtype=None):
|
||||
converted = data if is_duck_array(data) else xp.asarray(data)
|
||||
|
||||
--
|
||||
2.47.0
|
||||
|
||||
@@ -12,6 +12,11 @@ Source: %pypi_source %{srcname}
|
||||
# Fix test_dask_da_groupby_quantile.
|
||||
Patch: https://github.com/pydata/xarray/pull/9945.patch
|
||||
|
||||
# https://github.com/pydata/xarray/pull/9949
|
||||
Patch: 0001-Fix-test_doc_example-on-big-endian-systems.patch
|
||||
# https://github.com/pydata/xarray/pull/9964
|
||||
Patch: 0002-Avoid-unsafe-casts-from-float-to-unsigned-int.patch
|
||||
|
||||
BuildArch: noarch
|
||||
|
||||
BuildRequires: python3-devel
|
||||
|
||||
Reference in New Issue
Block a user