Skip to content

Commit 3610baa

Browse files
authored
Fix Pydap tests for numpy 2.3.0 changes (scalar string to unicode) (#10421)
* Fix Pydap test_cmp_local_file for numpy 2.3.0 changes * Apply suggestions from code review * fix another test
1 parent d8a4a05 commit 3610baa

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Deprecations
2424

2525
Bug fixes
2626
~~~~~~~~~
27+
- Fix Pydap test_cmp_local_file for numpy 2.3.0 changes, 1. do always return arrays for all versions and 2. skip astype(str) for numpy >= 2.3.0 for expected data. (:pull:`10421`)
28+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
2729

2830

2931
Documentation

xarray/tests/test_backends.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5417,11 +5417,12 @@ def convert_to_pydap_dataset(self, original):
54175417
@contextlib.contextmanager
54185418
def create_datasets(self, **kwargs):
54195419
with open_example_dataset("bears.nc") as expected:
5420+
# print("QQ0:", expected["bears"].load())
54205421
pydap_ds = self.convert_to_pydap_dataset(expected)
54215422
actual = open_dataset(PydapDataStore(pydap_ds))
5422-
# TODO solve this workaround:
5423-
# netcdf converts string to byte not unicode
5424-
expected["bears"] = expected["bears"].astype(str)
5423+
if Version(np.__version__) < Version("2.3.0"):
5424+
# netcdf converts string to byte not unicode
5425+
expected["bears"] = expected["bears"].astype(str)
54255426
yield actual, expected
54265427

54275428
def test_cmp_local_file(self) -> None:
@@ -5441,7 +5442,9 @@ def test_cmp_local_file(self) -> None:
54415442
assert_equal(actual[{"l": 2}], expected[{"l": 2}])
54425443

54435444
with self.create_datasets() as (actual, expected):
5444-
assert_equal(actual.isel(i=0, j=-1), expected.isel(i=0, j=-1))
5445+
# always return arrays and not scalars
5446+
# scalars will be promoted to unicode for numpy >= 2.3.0
5447+
assert_equal(actual.isel(i=[0], j=[-1]), expected.isel(i=[0], j=[-1]))
54455448

54465449
with self.create_datasets() as (actual, expected):
54475450
assert_equal(actual.isel(j=slice(1, 2)), expected.isel(j=slice(1, 2)))
@@ -5463,7 +5466,9 @@ def test_compatible_to_netcdf(self) -> None:
54635466
with create_tmp_file() as tmp_file:
54645467
actual.to_netcdf(tmp_file)
54655468
with open_dataset(tmp_file) as actual2:
5466-
actual2["bears"] = actual2["bears"].astype(str)
5469+
if Version(np.__version__) < Version("2.3.0"):
5470+
# netcdf converts string to byte not unicode
5471+
actual2["bears"] = actual2["bears"].astype(str)
54675472
assert_equal(actual2, expected)
54685473

54695474
@requires_dask

0 commit comments

Comments
 (0)