diff --git a/ci/requirements/min-all-deps.yml b/ci/requirements/min-all-deps.yml index b7698c0abd3..9183433e801 100644 --- a/ci/requirements/min-all-deps.yml +++ b/ci/requirements/min-all-deps.yml @@ -38,7 +38,7 @@ dependencies: - pandas=2.2 - pint=0.24 - pip - - pydap=3.5 + - pydap=3.5.0 - pytest - pytest-cov - pytest-env diff --git a/doc/whats-new.rst b/doc/whats-new.rst index cac5cb1ea8b..833ac23d449 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -117,6 +117,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. 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 `_. Documentation diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 2709e834e68..8289d729b43 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -5437,7 +5437,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) @@ -5449,9 +5451,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: @@ -5495,9 +5497,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 @@ -5515,9 +5514,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): @@ -5530,7 +5531,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: