Skip to content

Commit 5da6cca

Browse files
committed
test: proper skip behavior for zarr versions
1 parent fde770d commit 5da6cca

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
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.0.9")
134+
135+
# Additional check for zarr dtype support (dev versions > 3.0.9)
136+
if has_zarr:
137+
import zarr
138+
139+
# Dev versions like "3.0.9.dev47+g9da38f75" are > "3.0.9"
140+
has_zarr_v3_dtypes = has_zarr_v3_dtypes or (
141+
Version(zarr.__version__) > Version("3.0.9")
142+
)
143+
requires_zarr_v3_dtypes = pytest.mark.skipif(
144+
not has_zarr_v3_dtypes, reason="requires zarr>3.0.9 (including dev versions)"
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: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
has_scipy,
7373
has_zarr,
7474
has_zarr_v3,
75+
has_zarr_v3_dtypes,
7576
mock,
7677
network,
7778
requires_cftime,
@@ -369,14 +370,11 @@ def create_store(self):
369370
def roundtrip(
370371
self, data, save_kwargs=None, open_kwargs=None, allow_cleanup_failure=False
371372
):
372-
print("INT ROUNDTRIP")
373373
if save_kwargs is None:
374374
save_kwargs = {}
375375
if open_kwargs is None:
376376
open_kwargs = {}
377377
with create_tmp_file(allow_cleanup_failure=allow_cleanup_failure) as path:
378-
print(path)
379-
print(save_kwargs)
380378
self.save(data, path, **save_kwargs)
381379
with self.open(path, **open_kwargs) as ds:
382380
yield ds
@@ -851,16 +849,8 @@ def test_outer_indexing_reversed(self) -> None:
851849
{"z": (("t", "p", "y", "x"), np.ones((1, 1, 31, 40)))},
852850
)
853851

854-
print("jsda;lkjasdlfk")
855-
print(f"Test class: {self.__class__.__name__}")
856-
print(f"Dataset: {ds}")
857852
with self.roundtrip(ds) as on_disk:
858-
print(f"on_disk type: {type(on_disk)}")
859-
print(f"on_disk.z type: {type(on_disk.z)}")
860853
subset = on_disk.isel(t=[0], p=0).z[:, ::10, ::10][:, ::-1, :]
861-
print(f"subset sizes: {subset.sizes}")
862-
loaded = subset.load()
863-
print(f"loaded sizes: {loaded.sizes}")
864854
assert subset.sizes == subset.load().sizes
865855

866856
def test_isel_dataarray(self) -> None:
@@ -2918,6 +2908,9 @@ def test_append_with_existing_encoding_raises(self) -> None:
29182908

29192909
@pytest.mark.parametrize("dtype", ["U", "S"])
29202910
def test_append_string_length_mismatch_raises(self, dtype) -> None:
2911+
if has_zarr_v3() and not has_zarr_v3_dtypes:
2912+
pytest.skip("This works on pre dtype updated zarr python")
2913+
29212914
ds, ds_to_append = create_append_string_length_mismatch_test_data(dtype)
29222915
with self.create_zarr_target() as store_target:
29232916
ds.to_zarr(store_target, mode="w", **self.version_kwargs)

0 commit comments

Comments
 (0)