Skip to content

Commit 9981eea

Browse files
committed
remove warning, and instead error when creating v3 arrays with storage transformers
1 parent c158f87 commit 9981eea

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

src/zarr/core/array.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ def parse_array_metadata(data: Any) -> ArrayV2Metadata | ArrayV3Metadata:
7979
return data
8080
elif isinstance(data, dict):
8181
if data["zarr_format"] == 3:
82-
return ArrayV3Metadata.from_dict(data)
82+
meta_out = ArrayV3Metadata.from_dict(data)
83+
if len(meta_out.storage_transformers) > 0:
84+
msg = (
85+
f"Array metadata contains storage transformers: {meta_out.storage_transformers}."
86+
"Arrays with storage transformers are not supported in zarr-python at this time."
87+
)
88+
raise ValueError(msg)
89+
return meta_out
8390
elif data["zarr_format"] == 2:
8491
return ArrayV2Metadata.from_dict(data)
8592
raise TypeError

src/zarr/core/metadata/v3.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import warnings
43
from typing import TYPE_CHECKING, cast, overload
54

65
if TYPE_CHECKING:
@@ -72,24 +71,20 @@ def parse_dimension_names(data: object) -> tuple[str | None, ...] | None:
7271

7372

7473
def parse_storage_transformers(data: object) -> tuple[dict[str, JSON], ...]:
74+
"""
75+
Parse storage_transformers. Zarr python cannot use storage transformers
76+
at this time, so this function doesn't attempt to validate them.
77+
"""
7578
if data is None:
7679
return ()
7780
if isinstance(data, Iterable):
7881
if len(tuple(data)) >= 1:
79-
msg = (
80-
"Got a non-null storage_transformers keyword argument. "
81-
"Storage transformers are not supported by zarr-python at this time. "
82-
"The storage transformer(s) will be retained in array metadata but will not "
83-
"influence storage routines"
84-
)
85-
warnings.warn(msg, UserWarning, stacklevel=1)
8682
return data # type: ignore[return-value]
8783
else:
8884
return ()
89-
else:
90-
raise TypeError(
91-
f"Invalid storage_transformers. Expected an iterable of dicts. Got {type(data)} instead."
92-
)
85+
raise TypeError(
86+
f"Invalid storage_transformers. Expected an iterable of dicts. Got {type(data)} instead."
87+
)
9388

9489

9590
@dataclass(frozen=True, kw_only=True)

tests/v3/test_array.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import pytest
66

77
from zarr import Array, AsyncArray, Group
8-
from zarr.core.common import ZarrFormat
8+
from zarr.codecs.bytes import BytesCodec
9+
from zarr.core.common import JSON, ZarrFormat
910
from zarr.errors import ContainsArrayError, ContainsGroupError
1011
from zarr.store import LocalStore, MemoryStore
1112
from zarr.store.common import StorePath
@@ -188,3 +189,24 @@ def test_serializable_sync_array(store: LocalStore, zarr_format: ZarrFormat) ->
188189

189190
assert actual == expected
190191
np.testing.assert_array_equal(actual[:], expected[:])
192+
193+
194+
@pytest.mark.parametrize("store", ("memory",), indirect=True)
195+
def test_storage_transformers(store: MemoryStore) -> None:
196+
"""
197+
Test that providing an actual storage transformer produces a warning and otherwise passes through
198+
"""
199+
metadata_dict: dict[str, JSON] = {
200+
"zarr_format": 3,
201+
"node_type": "array",
202+
"shape": (10,),
203+
"chunk_grid": {"name": "regular", "configuration": {"chunk_shape": (1,)}},
204+
"data_type": "uint8",
205+
"chunk_key_encoding": {"name": "v2", "configuration": {"separator": "/"}},
206+
"codecs": (BytesCodec().to_dict(),),
207+
"fill_value": 0,
208+
"storage_transformers": ({"test": "should_raise"}),
209+
}
210+
match = "Arrays with storage transformers are not supported in zarr-python at this time."
211+
with pytest.raises(ValueError, match=match):
212+
Array.from_dict(StorePath(store), data=metadata_dict)

tests/v3/test_metadata/test_v3.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,3 @@ async def test_datetime_metadata(fill_value: int, precision: str) -> None:
264264

265265
result = json.loads(d["zarr.json"].to_bytes())
266266
assert result["fill_value"] == fill_value
267-
268-
269-
def test_storage_transformers() -> None:
270-
"""
271-
Test that providing an actual storage transformer produces a warning and otherwise passes through
272-
"""
273-
metadata_dict = {
274-
"zarr_format": 3,
275-
"node_type": "array",
276-
"shape": (10,),
277-
"chunk_grid": {"name": "regular", "configuration": {"chunk_shape": (1,)}},
278-
"data_type": "uint8",
279-
"chunk_key_encoding": {"name": "v2", "configuration": {"separator": "/"}},
280-
"codecs": (BytesCodec(),),
281-
"fill_value": 0,
282-
"storage_transformers": ({"test": "should_warn"}),
283-
}
284-
with pytest.warns():
285-
meta = ArrayV3Metadata.from_dict(metadata_dict)
286-
287-
assert meta.to_dict()["storage_transformers"] == metadata_dict["storage_transformers"]

0 commit comments

Comments
 (0)