Skip to content

Check if zarr store supports consolidated metadata #10457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
01e7518
new blank whatsnew
TomNicholas Oct 24, 2024
83e553b
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Oct 24, 2024
e44326d
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Nov 8, 2024
4e4eeb0
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Nov 20, 2024
d858059
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Nov 21, 2024
d377780
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Nov 21, 2024
3132f6a
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Nov 23, 2024
900eef5
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Nov 29, 2024
4c4462f
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Dec 4, 2024
5b9b749
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jan 6, 2025
fadb953
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jan 8, 2025
57d9d23
Merge branch 'main' of https://github.com/TomNicholas/xarray
TomNicholas Mar 13, 2025
11170fc
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Mar 19, 2025
0b8fa41
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Mar 20, 2025
f769f85
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Mar 20, 2025
4eef318
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Apr 7, 2025
29242a4
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas May 15, 2025
5d15bbd
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas May 19, 2025
b4ed8ee
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jun 20, 2025
6a23bfb
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jun 24, 2025
d87b209
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jun 27, 2025
08cb041
add test for store which explicitly does not support consolidated met…
TomNicholas Jun 27, 2025
9cc9105
check for consolidated metadata support
TomNicholas Jun 27, 2025
c817869
WrapperStore now only imported and used if zarr v3
TomNicholas Jun 28, 2025
50cff3e
use dedicated decorator
TomNicholas Jun 28, 2025
a47b2e2
use getattr in case property not defined
TomNicholas Jun 28, 2025
76f16fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
9b39529
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jun 28, 2025
e174d9c
implement with_read_only
TomNicholas Jun 30, 2025
5b441b2
Merge branch 'check_supports_consolidated_metadata' of https://github…
TomNicholas Jun 30, 2025
e395c60
Merge branch 'main' into check_supports_consolidated_metadata
TomNicholas Jul 1, 2025
1829807
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jul 1, 2025
de02ced
Merge branch 'main' of https://github.com/pydata/xarray
TomNicholas Jul 2, 2025
8167b83
Merge branch 'main' into check_supports_consolidated_metadata
TomNicholas Jul 2, 2025
1e30664
Merge branch 'check_supports_consolidated_metadata' of https://github…
TomNicholas Jul 2, 2025
101b280
change test to not expect warning if consolidated metadata not supported
TomNicholas Jul 2, 2025
26a402c
move store definition outside of test
TomNicholas Jul 2, 2025
1ce9d87
try setting Store=None when zarr-python v3 not installed
TomNicholas Jul 2, 2025
ad4d79c
remove Store type hint entirely to avoid import issues
TomNicholas Jul 2, 2025
09915dd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 2, 2025
8252f9f
try WrapperStore = object
TomNicholas Jul 2, 2025
e550851
ensure WrapperStore is defined as something even if zarr isn't presen…
TomNicholas Jul 2, 2025
470e701
Merge branch 'main' into check_supports_consolidated_metadata
TomNicholas Jul 2, 2025
586c7a2
release note
TomNicholas Jul 2, 2025
e673608
Merge branch 'check_supports_consolidated_metadata' of https://github…
TomNicholas Jul 2, 2025
758eea4
correct RST syntax
TomNicholas Jul 2, 2025
e3f0d7b
Merge branch 'main' into check_supports_consolidated_metadata
TomNicholas Jul 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,10 @@ def _get_open_params(
else:
missing_exc = zarr.errors.GroupNotFoundError

if _zarr_v3():
if not store.supports_consolidated_metadata:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not store.supports_consolidated_metadata:
if not getattr(store, "supports_consolidated_metadata", True):

I think this will be needed for Zarr >3.0.0,<3.1.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - I had something like that then removed it 🤦

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in a47b2e2

consolidated = consolidate_on_close = False

if consolidated in [None, True]:
# open the root of the store, in case there is metadata consolidated there
group = open_kwargs.pop("path")
Expand Down Expand Up @@ -1825,6 +1829,7 @@ def _get_open_params(
else:
# this was the default for v2 and should apply to most existing Zarr data
use_zarr_fill_value_as_mask = True

return (
zarr_group,
consolidate_on_close,
Expand Down
25 changes: 25 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
import zarr.codecs

if has_zarr_v3:
from zarr.abc.store import Store
from zarr.storage import MemoryStore as KVStore
from zarr.storage import WrapperStore

ZARR_FORMATS = [2, 3]
else:
Expand Down Expand Up @@ -1062,7 +1064,7 @@
encoded = Dataset({"x": ("t", sb, attributes)})
unsigned_dtype = np.dtype(f"u{sb.dtype.itemsize}")

with _roundtrip_with_warnings(decoded) as actual:

Check failure on line 1067 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_roundtrip_unsigned[2-255-True] Failed: DID NOT WARN. No warnings of type (<class 'xarray.coding.common.SerializationWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 1067 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_roundtrip_unsigned[2--1-False] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 1067 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_roundtrip_unsigned[2-fill_value1-True] Failed: DID NOT WARN. No warnings of type (<class 'xarray.coding.common.SerializationWarning'>,) were emitted. Emitted warnings: [].
for k in decoded.variables:
assert decoded.variables[k].dtype == actual.variables[k].dtype
exp_fv = decoded.variables[k].encoding["_FillValue"]
Expand Down Expand Up @@ -1138,7 +1140,7 @@

def test_grid_mapping_and_bounds_are_not_coordinates_in_file(self) -> None:
original = self._create_cf_dataset()
with self.roundtrip(original, open_kwargs={"decode_coords": False}) as ds:

Check failure on line 1143 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_grid_mapping_and_bounds_are_not_coordinates_in_file[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
assert ds.coords["latitude"].attrs["bounds"] == "latitude_bnds"
assert ds.coords["longitude"].attrs["bounds"] == "longitude_bnds"
assert "coordinates" not in ds["variable"].attrs
Expand All @@ -1146,7 +1148,7 @@

def test_coordinate_variables_after_dataset_roundtrip(self) -> None:
original = self._create_cf_dataset()
with self.roundtrip(original, open_kwargs={"decode_coords": "all"}) as actual:

Check failure on line 1151 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_coordinate_variables_after_dataset_roundtrip[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
assert_identical(actual, original)

with self.roundtrip(original) as actual:
Expand All @@ -1171,7 +1173,7 @@
# xarray/tests/test_conventions.py::TestCFEncodedDataStore
# needs the to_dataset. The other backends should be fine
# without it.
with pytest.warns(

Check failure on line 1176 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[2] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].
UserWarning,
match=(
r"Variable\(s\) referenced in bounds not in variables: "
Expand Down Expand Up @@ -1203,7 +1205,7 @@
{"temp": ("x", [0, 1]), "precip": ("x", [0, -1])},
{"lat": ("x", [2, 3]), "lon": ("x", [4, 5])},
)
with self.roundtrip(original) as actual:

Check failure on line 1208 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_coordinates_encoding[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
assert_identical(actual, original)
with self.roundtrip(original, open_kwargs=dict(decode_coords=False)) as ds:
assert equals_latlon(ds["temp"].attrs["coordinates"])
Expand Down Expand Up @@ -1241,7 +1243,7 @@
}
)

with self.roundtrip(ds) as actual:

Check failure on line 1246 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_roundtrip_endian[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
# technically these datasets are slightly different,
# one hold mixed endian data (ds) the other should be
# all big endian (actual). assertDatasetIdentical
Expand Down Expand Up @@ -1273,7 +1275,7 @@
ds = Dataset({"x": ("y", np.arange(10.0))})

kwargs: dict[str, Any] = dict(encoding={"x": {"dtype": "f4"}})
with self.roundtrip(ds, save_kwargs=kwargs) as actual:

Check failure on line 1278 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_encoding_kwarg[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
encoded_dtype = actual.x.encoding["dtype"]
# On OS X, dtype sometimes switches endianness for unclear reasons
assert encoded_dtype.kind == "f" and encoded_dtype.itemsize == 4
Expand All @@ -1298,7 +1300,7 @@
ds = Dataset({"t": pd.date_range("2000-01-01", periods=3)})
units = "days since 1900-01-01"
kwargs = dict(encoding={"t": {"units": units}})
with self.roundtrip(ds, save_kwargs=kwargs) as actual:

Check failure on line 1303 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-dask

TestZarrWriteEmpty.test_encoding_kwarg_dates[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
assert actual.t.encoding["units"] == units
assert_identical(actual, ds)

Expand Down Expand Up @@ -1351,20 +1353,20 @@
def test_explicitly_omit_fill_value_in_coord(self) -> None:
ds = Dataset({"x": ("y", [np.pi, -np.pi])}, coords={"y": [0.0, 1.0]})
ds.y.encoding["_FillValue"] = None
with self.roundtrip(ds) as actual:

Check failure on line 1356 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_explicitly_omit_fill_value_in_coord[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
assert "_FillValue" not in actual.y.encoding

def test_explicitly_omit_fill_value_in_coord_via_encoding_kwarg(self) -> None:
ds = Dataset({"x": ("y", [np.pi, -np.pi])}, coords={"y": [0.0, 1.0]})
kwargs = dict(encoding={"y": {"_FillValue": None}})
with self.roundtrip(ds, save_kwargs=kwargs) as actual:

Check failure on line 1362 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_explicitly_omit_fill_value_in_coord_via_encoding_kwarg[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
assert "_FillValue" not in actual.y.encoding
assert ds.y.encoding == {}

def test_encoding_same_dtype(self) -> None:
ds = Dataset({"x": ("y", np.arange(10.0, dtype="f4"))})
kwargs = dict(encoding={"x": {"dtype": "f4"}})
with self.roundtrip(ds, save_kwargs=kwargs) as actual:

Check failure on line 1369 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_encoding_same_dtype[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
encoded_dtype = actual.x.encoding["dtype"]
# On OS X, dtype sometimes switches endianness for unclear reasons
assert encoded_dtype.kind == "f" and encoded_dtype.itemsize == 4
Expand All @@ -1380,7 +1382,7 @@
# regression for GH1215
data = create_test_data()
with create_tmp_file(allow_cleanup_failure=False) as tmp_file:
self.save(data, tmp_file, mode="w")

Check failure on line 1385 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_append_overwrite_values[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
data["var2"][:] = -999
data["var9"] = data["var2"] * 3
self.save(data[["var2", "var9"]], tmp_file, mode="a")
Expand All @@ -1403,7 +1405,7 @@
x=["y", "z"]
)
with pytest.raises(NotImplementedError, match=r"MultiIndex"):
with self.roundtrip(ds):

Check failure on line 1408 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_multiindex_not_implemented[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
pass

# regression GH8628 (can serialize reset multi-index level coordinates)
Expand All @@ -1423,7 +1425,7 @@
)
}
).chunk()
with pytest.warns(SerializationWarning, match="dask array with dtype=object"):

Check failure on line 1428 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_string_object_warning[2] Failed: DID NOT WARN. No warnings of type (<class 'xarray.coding.common.SerializationWarning'>,) were emitted. Emitted warnings: [].
with self.roundtrip(original) as actual:
assert_identical(original, actual)

Expand All @@ -1441,7 +1443,7 @@
# regression test for GH8909
ds = xr.Dataset()
ds["A"] = xr.DataArray([[1, "a"], [2, "b"]], dims=["x", "y"])
with self.roundtrip(ds) as ds2:

Check failure on line 1446 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_indexing_roundtrip[2-indexer3] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 1446 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_indexing_roundtrip[2-indexer2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 1446 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_indexing_roundtrip[2-indexer1] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 1446 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13 all-but-numba

TestZarrDirectoryStore.test_indexing_roundtrip[2-indexer0] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
expected = ds2.sel(indexer)
with self.roundtrip(expected) as actual:
assert_identical(actual, expected)
Expand Down Expand Up @@ -2375,7 +2377,7 @@
@pytest.mark.parametrize("consolidated", [False, True, None])
def test_roundtrip_consolidated(self, consolidated) -> None:
expected = create_test_data()
with self.roundtrip(

Check failure on line 2380 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_roundtrip_consolidated[2-None] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2380 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_roundtrip_consolidated[2-True] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2380 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_roundtrip_consolidated[2-False] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2380 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_roundtrip_consolidated[2-None] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2380 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_roundtrip_consolidated[2-True] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2380 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_roundtrip_consolidated[2-False] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
expected,
save_kwargs={"consolidated": consolidated},
open_kwargs={"backend_kwargs": {"consolidated": consolidated}},
Expand All @@ -2386,7 +2388,7 @@
def test_read_non_consolidated_warning(self) -> None:
expected = create_test_data()
with self.create_zarr_target() as store:
self.save(

Check failure on line 2391 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_read_non_consolidated_warning[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2391 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_read_non_consolidated_warning[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
expected, store_target=store, consolidated=False, **self.version_kwargs
)
with pytest.warns(
Expand All @@ -2400,7 +2402,7 @@
with pytest.raises(
FileNotFoundError, match="(No such file or directory|Unable to find group)"
):
xr.open_zarr(f"{uuid.uuid4()}")

Check failure on line 2405 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_non_existent_store[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2405 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_non_existent_store[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

@pytest.mark.skipif(has_zarr_v3, reason="chunk_store not implemented in zarr v3")
def test_with_chunkstore(self) -> None:
Expand All @@ -2421,7 +2423,7 @@
def test_auto_chunk(self) -> None:
original = create_test_data().chunk()

with self.roundtrip(original, open_kwargs={"chunks": None}) as actual:

Check failure on line 2426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_auto_chunk[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_auto_chunk[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
for k, v in actual.variables.items():
# only index variables should be in memory
assert v._in_memory == (k in actual.dims)
Expand All @@ -2442,7 +2444,7 @@

# Using chunks = None should return non-chunked arrays
open_kwargs: dict[str, Any] = {"chunks": None}
with self.roundtrip(original, open_kwargs=open_kwargs) as actual:

Check failure on line 2447 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_manual_chunk[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2447 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_manual_chunk[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
for k, v in actual.variables.items():
# only index variables should be in memory
assert v._in_memory == (k in actual.dims)
Expand Down Expand Up @@ -2486,7 +2488,7 @@
bad_chunks = (2, {"dim2": (3, 3, 2, 1)})
for chunks in bad_chunks:
kwargs = {"chunks": chunks}
with pytest.warns(UserWarning):

Check failure on line 2491 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_warning_on_bad_chunks[2] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 2491 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_warning_on_bad_chunks[2] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].
with self.roundtrip(original, open_kwargs=kwargs) as actual:
for k, v in actual.variables.items():
# only index variables should be in memory
Expand All @@ -2511,7 +2513,7 @@
def test_deprecate_auto_chunk(self) -> None:
original = create_test_data().chunk()
with pytest.raises(TypeError):
with self.roundtrip(original, open_kwargs={"auto_chunk": True}) as actual:

Check failure on line 2516 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_deprecate_auto_chunk[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2516 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_deprecate_auto_chunk[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
for k, v in actual.variables.items():
# only index variables should be in memory
assert v._in_memory == (k in actual.dims)
Expand All @@ -2530,7 +2532,7 @@
def test_write_uneven_dask_chunks(self) -> None:
# regression for GH#2225
original = create_test_data().chunk({"dim1": 3, "dim2": 4, "dim3": 3})
with self.roundtrip(original, open_kwargs={"chunks": {}}) as actual:

Check failure on line 2535 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.13

TestZarrDirectoryStore.test_write_uneven_dask_chunks[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'

Check failure on line 2535 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.13

TestZarrDirectoryStore.test_write_uneven_dask_chunks[2] AttributeError: 'str' object has no attribute 'supports_consolidated_metadata'
for k, v in actual.data_vars.items():
assert v.chunks == actual[k].chunks

Expand Down Expand Up @@ -3744,6 +3746,29 @@
assert actual["var1"].encoding["chunks"] == (2, 2)


class NoConsolidatedMetadataSupportStore(WrapperStore[Store]):
Copy link
Member Author

@TomNicholas TomNicholas Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: I don't think I even want to try and define this class if zarr-python v3 is not installed

"""
Store that explicitly does not support consolidated metadata.

Useful as a proxy for stores like Icechunk, see https://github.com/zarr-developers/zarr-python/pull/3119.
"""

supports_consolidated_metadata = False


@requires_zarr
class TestZarrNoConsolidatedMetadataSupport(ZarrBase):
@contextlib.contextmanager
def create_zarr_target(self):
# TODO the zarr version would need to be >3.08 for the supports_consolidated_metadata property to have any effect
if has_zarr_v3:
yield NoConsolidatedMetadataSupportStore(
zarr.storage.MemoryStore({}, read_only=False)
)
else:
pytest.skip("requires zarr v3")


@requires_zarr
@pytest.mark.skipif(
ON_WINDOWS,
Expand Down
Loading