From 6be02af6cd07ce9059a9b545592269107a55b473 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez-Urias Date: Tue, 1 Jul 2025 11:35:32 -0700 Subject: [PATCH 1/6] force string array elements to be dtype=`S` for testing, avoid unicode --- xarray/tests/test_backends.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 733188dde1e..282dc1d17da 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -5425,7 +5425,9 @@ def convert_to_pydap_dataset(self, original): ds = DatasetType("bears", **original.attrs) for key, var in original.data_vars.items(): - ds[key] = BaseType(key, var.values, dims=var.dims, **var.attrs) + ds[key] = BaseType( + key, var.values, dtype=var.values.dtype.kind, dims=var.dims, **var.attrs + ) # check all dims are stored in ds for d in original.coords: ds[d] = BaseType(d, original[d].values, dims=(d,), **original[d].attrs) @@ -5437,9 +5439,9 @@ def create_datasets(self, **kwargs): # print("QQ0:", expected["bears"].load()) pydap_ds = self.convert_to_pydap_dataset(expected) actual = open_dataset(PydapDataStore(pydap_ds)) - if Version(np.__version__) < Version("2.3.0"): - # netcdf converts string to byte not unicode - expected["bears"] = expected["bears"].astype(str) + # netcdf converts string to byte not unicode + # fixed in pydap 3.5.6. https://github.com/pydap/pydap/issues/510 + actual["bears"].values = actual["bears"].values.astype("S") yield actual, expected def test_cmp_local_file(self) -> None: @@ -5483,9 +5485,6 @@ def test_compatible_to_netcdf(self) -> None: with create_tmp_file() as tmp_file: actual.to_netcdf(tmp_file) with open_dataset(tmp_file) as actual2: - if Version(np.__version__) < Version("2.3.0"): - # netcdf converts string to byte not unicode - actual2["bears"] = actual2["bears"].astype(str) assert_equal(actual2, expected) @requires_dask @@ -5503,9 +5502,11 @@ def create_dap2_datasets(self, **kwargs): # in pydap 3.5.0, urls defaults to dap2. url = "http://test.opendap.org/opendap/data/nc/bears.nc" actual = open_dataset(url, engine="pydap", **kwargs) + # pydap <3.5.6 converts to unicode dtype=|U. Not what + # xarray expects. Thus force to bytes dtype. pydap >=3.5.6 + # does not convert to unicode. https://github.com/pydap/pydap/issues/510 + actual["bears"].values = actual["bears"].values.astype("S") with open_example_dataset("bears.nc") as expected: - # workaround to restore string which is converted to byte - expected["bears"] = expected["bears"].astype(str) yield actual, expected def output_grid_deprecation_warning_dap2dataset(self): @@ -5518,7 +5519,8 @@ def create_dap4_dataset(self, **kwargs): actual = open_dataset(url, engine="pydap", **kwargs) with open_example_dataset("bears.nc") as expected: # workaround to restore string which is converted to byte - expected["bears"] = expected["bears"].astype(str) + # only needed for pydap <3.5.6 https://github.com/pydap/pydap/issues/510 + expected["bears"].values = expected["bears"].values.astype("S") yield actual, expected def test_session(self) -> None: From f3733b935794f9b18ff3aa89ef11519f04ceb8c6 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez-Urias Date: Tue, 1 Jul 2025 11:40:37 -0700 Subject: [PATCH 2/6] restore min version of pydap=3.5.0 to adhere to policy --- ci/requirements/min-all-deps.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/requirements/min-all-deps.yml b/ci/requirements/min-all-deps.yml index 03e14773d53..f2ff924f66d 100644 --- a/ci/requirements/min-all-deps.yml +++ b/ci/requirements/min-all-deps.yml @@ -1,4 +1,4 @@ -name: xarray-tests +name: xarray-tests_min channels: - conda-forge - nodefaults @@ -42,7 +42,7 @@ dependencies: - pandas=2.1 - pint=0.22 - pip - - pydap=3.5 + - pydap=3.5.0 - pytest - pytest-cov - pytest-env From d8f4b853562ecc9b768fc6ad7c1a3360b8217b0c Mon Sep 17 00:00:00 2001 From: Miguel Jimenez-Urias Date: Tue, 1 Jul 2025 12:04:09 -0700 Subject: [PATCH 3/6] add what`s new --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 31d3a1077e7..926849d84db 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -36,6 +36,8 @@ Bug fixes are passed (:pull:`10440`). By `Mathias Hauser `_. - Fix :py:func:`testing.assert_equal` with ``check_dim_order=False`` for :py:class:`DataTree` objects (:pull:`10442`). By `Mathias Hauser `_. +- Fix Pydap backend testing. Not test forces string arrays to dtype "|S" (pydap converts them to unicode type by default). Removes conditional to numpy version. (:issue:`10261`,:pull:`10482`) + By `Miguel Jimenez-Urias `_. Documentation From 12be607aab831776f66abbb5b8d8d4d76f4b13fa Mon Sep 17 00:00:00 2001 From: Miguel Jimenez-Urias Date: Tue, 1 Jul 2025 12:05:25 -0700 Subject: [PATCH 4/6] fix test env name --- ci/requirements/min-all-deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/requirements/min-all-deps.yml b/ci/requirements/min-all-deps.yml index f2ff924f66d..fc55280a17b 100644 --- a/ci/requirements/min-all-deps.yml +++ b/ci/requirements/min-all-deps.yml @@ -1,4 +1,4 @@ -name: xarray-tests_min +name: xarray-tests channels: - conda-forge - nodefaults From f651f6bce9a792a421cdee364afc54b7f50cd0f1 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez-Urias Date: Tue, 1 Jul 2025 12:07:52 -0700 Subject: [PATCH 5/6] fix what`s new text --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 926849d84db..3d711646da0 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -36,7 +36,7 @@ Bug fixes are passed (:pull:`10440`). By `Mathias Hauser `_. - Fix :py:func:`testing.assert_equal` with ``check_dim_order=False`` for :py:class:`DataTree` objects (:pull:`10442`). By `Mathias Hauser `_. -- Fix Pydap backend testing. Not test forces string arrays to dtype "|S" (pydap converts them to unicode type by default). Removes conditional to numpy version. (:issue:`10261`,:pull:`10482`) +- Fix Pydap backend testing. Now test forces string arrays to dtype "|S" (pydap converts them to unicode type by default). Removes conditional to numpy version. (:issue:`10261`, :pull:`10482`) By `Miguel Jimenez-Urias `_. From a7140a352435c47f9905bb2de3603558301806bb Mon Sep 17 00:00:00 2001 From: Miguel Jimenez-Urias Date: Tue, 1 Jul 2025 14:52:15 -0700 Subject: [PATCH 6/6] fix character on docs. These build locally now --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 3d711646da0..822bbaf5410 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -36,7 +36,7 @@ Bug fixes are passed (:pull:`10440`). By `Mathias Hauser `_. - Fix :py:func:`testing.assert_equal` with ``check_dim_order=False`` for :py:class:`DataTree` objects (:pull:`10442`). By `Mathias Hauser `_. -- Fix Pydap backend testing. Now test forces string arrays to dtype "|S" (pydap converts them to unicode type by default). Removes conditional to numpy version. (:issue:`10261`, :pull:`10482`) +- Fix Pydap backend testing. Now test forces string arrays to dtype "S" (pydap converts them to unicode type by default). Removes conditional to numpy version. (:issue:`10261`, :pull:`10482`) By `Miguel Jimenez-Urias `_.