diff --git a/xarray/tests/__init__.py b/xarray/tests/__init__.py index fe76df75fa0..4de9e422761 100644 --- a/xarray/tests/__init__.py +++ b/xarray/tests/__init__.py @@ -130,6 +130,20 @@ def _importorskip( has_rasterio, requires_rasterio = _importorskip("rasterio") has_zarr, requires_zarr = _importorskip("zarr") has_zarr_v3, requires_zarr_v3 = _importorskip("zarr", "3.0.0") +has_zarr_v3_dtypes, requires_zarr_v3_dtypes = _importorskip("zarr", "3.1.0") +if has_zarr_v3: + import zarr + + # manual update by checking attrs for now + # TODO: use version specifier + # installing from git main is giving me a lower version than the + # most recently released zarr + has_zarr_v3_dtypes = hasattr(zarr.core, "dtype") + + requires_zarr_v3_dtypes = pytest.mark.skipif( + not has_zarr_v3_dtypes, reason="requires zarr>3.1.0" + ) + has_fsspec, requires_fsspec = _importorskip("fsspec") has_iris, requires_iris = _importorskip("iris") has_numbagg, requires_numbagg = _importorskip("numbagg") diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index a9063c4dcc9..32ebe52c6ea 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -73,6 +73,7 @@ has_scipy, has_zarr, has_zarr_v3, + has_zarr_v3_dtypes, mock, network, requires_cftime, @@ -2437,7 +2438,7 @@ def test_read_non_consolidated_warning(self) -> None: def test_non_existent_store(self) -> None: with pytest.raises( FileNotFoundError, - match="(No such file or directory|Unable to find group|No group found)", + match="(No such file or directory|Unable to find group|No group found in store)", ): xr.open_zarr(f"{uuid.uuid4()}") @@ -2519,6 +2520,7 @@ def test_manual_chunk(self) -> None: assert_identical(actual.load(), auto.load()) @requires_dask + @pytest.mark.filterwarnings("ignore:.*does not have a Zarr V3 specification.*") def test_warning_on_bad_chunks(self) -> None: original = create_test_data().chunk({"dim1": 4, "dim2": 3, "dim3": 3}) @@ -2927,7 +2929,9 @@ def test_append_with_existing_encoding_raises(self) -> None: @pytest.mark.parametrize("dtype", ["U", "S"]) def test_append_string_length_mismatch_raises(self, dtype) -> None: - skip_if_zarr_format_3("This actually works fine with Zarr format 3") + if has_zarr_v3 and not has_zarr_v3_dtypes: + skip_if_zarr_format_3("This actually works fine with Zarr format 3") + ds, ds_to_append = create_append_string_length_mismatch_test_data(dtype) with self.create_zarr_target() as store_target: ds.to_zarr(store_target, mode="w", **self.version_kwargs) @@ -2940,8 +2944,12 @@ def test_append_string_length_mismatch_raises(self, dtype) -> None: def test_append_string_length_mismatch_works(self, dtype) -> None: skip_if_zarr_format_2("This doesn't work with Zarr format 2") # ...but it probably would if we used object dtype + if has_zarr_v3_dtypes: + pytest.skip("This works on pre ZDtype Zarr-Python, but fails after.") + ds, ds_to_append = create_append_string_length_mismatch_test_data(dtype) expected = xr.concat([ds, ds_to_append], dim="time") + with self.create_zarr_target() as store_target: ds.to_zarr(store_target, mode="w", **self.version_kwargs) ds_to_append.to_zarr(store_target, append_dim="time", **self.version_kwargs)