Skip to content

Commit 5f3907f

Browse files
ianhidcherian
andauthored
Updates for Zarr 3 Dtypes (#10456)
Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
1 parent 271ebe9 commit 5f3907f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

xarray/tests/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ def _importorskip(
130130
has_rasterio, requires_rasterio = _importorskip("rasterio")
131131
has_zarr, requires_zarr = _importorskip("zarr")
132132
has_zarr_v3, requires_zarr_v3 = _importorskip("zarr", "3.0.0")
133+
has_zarr_v3_dtypes, requires_zarr_v3_dtypes = _importorskip("zarr", "3.1.0")
134+
if has_zarr_v3:
135+
import zarr
136+
137+
# manual update by checking attrs for now
138+
# TODO: use version specifier
139+
# installing from git main is giving me a lower version than the
140+
# most recently released zarr
141+
has_zarr_v3_dtypes = hasattr(zarr.core, "dtype")
142+
143+
requires_zarr_v3_dtypes = pytest.mark.skipif(
144+
not has_zarr_v3_dtypes, reason="requires zarr>3.1.0"
145+
)
146+
133147
has_fsspec, requires_fsspec = _importorskip("fsspec")
134148
has_iris, requires_iris = _importorskip("iris")
135149
has_numbagg, requires_numbagg = _importorskip("numbagg")

xarray/tests/test_backends.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
has_scipy,
7474
has_zarr,
7575
has_zarr_v3,
76+
has_zarr_v3_dtypes,
7677
mock,
7778
network,
7879
requires_cftime,
@@ -2437,7 +2438,7 @@ def test_read_non_consolidated_warning(self) -> None:
24372438
def test_non_existent_store(self) -> None:
24382439
with pytest.raises(
24392440
FileNotFoundError,
2440-
match="(No such file or directory|Unable to find group|No group found)",
2441+
match="(No such file or directory|Unable to find group|No group found in store)",
24412442
):
24422443
xr.open_zarr(f"{uuid.uuid4()}")
24432444

@@ -2519,6 +2520,7 @@ def test_manual_chunk(self) -> None:
25192520
assert_identical(actual.load(), auto.load())
25202521

25212522
@requires_dask
2523+
@pytest.mark.filterwarnings("ignore:.*does not have a Zarr V3 specification.*")
25222524
def test_warning_on_bad_chunks(self) -> None:
25232525
original = create_test_data().chunk({"dim1": 4, "dim2": 3, "dim3": 3})
25242526

@@ -2927,7 +2929,9 @@ def test_append_with_existing_encoding_raises(self) -> None:
29272929

29282930
@pytest.mark.parametrize("dtype", ["U", "S"])
29292931
def test_append_string_length_mismatch_raises(self, dtype) -> None:
2930-
skip_if_zarr_format_3("This actually works fine with Zarr format 3")
2932+
if has_zarr_v3 and not has_zarr_v3_dtypes:
2933+
skip_if_zarr_format_3("This actually works fine with Zarr format 3")
2934+
29312935
ds, ds_to_append = create_append_string_length_mismatch_test_data(dtype)
29322936
with self.create_zarr_target() as store_target:
29332937
ds.to_zarr(store_target, mode="w", **self.version_kwargs)
@@ -2940,8 +2944,12 @@ def test_append_string_length_mismatch_raises(self, dtype) -> None:
29402944
def test_append_string_length_mismatch_works(self, dtype) -> None:
29412945
skip_if_zarr_format_2("This doesn't work with Zarr format 2")
29422946
# ...but it probably would if we used object dtype
2947+
if has_zarr_v3_dtypes:
2948+
pytest.skip("This works on pre ZDtype Zarr-Python, but fails after.")
2949+
29432950
ds, ds_to_append = create_append_string_length_mismatch_test_data(dtype)
29442951
expected = xr.concat([ds, ds_to_append], dim="time")
2952+
29452953
with self.create_zarr_target() as store_target:
29462954
ds.to_zarr(store_target, mode="w", **self.version_kwargs)
29472955
ds_to_append.to_zarr(store_target, append_dim="time", **self.version_kwargs)

0 commit comments

Comments
 (0)