Skip to content

Commit 07c56b7

Browse files
committed
clean up array creation exceptions
1 parent 536b0e6 commit 07c56b7

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

src/zarr/core/array.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ async def get_array_metadata(
192192
if zarr_json_bytes is not None and zarray_bytes is not None:
193193
# warn and favor v3
194194
msg = (
195-
"Both zarr.json (Zarr format 3) and .zarray (Zarr format 2) metadata objects "
196-
f"exist in store {store_path.store!r} at path {store_path.path!r}. "
195+
"Both Zarr V3 Zarr V2 metadata documents "
196+
f"were found in store {store_path.store!r} at path {store_path.path!r}. "
197197
"The Zarr V3 metadata will be used."
198198
"To open Zarr V2 arrays, set zarr_format=2."
199199
)
200200
warnings.warn(msg, stacklevel=1)
201201
if zarr_json_bytes is None and zarray_bytes is None:
202202
msg = (
203-
f"Neither zarr.json (Zarr format 3) nor .zarray (Zarr format 2) metadata objects "
204-
f"exist in store {store_path.store!r} at path {store_path.path!r}."
203+
f"Neither Zarr V3 nor Zarr V2 array metadata documents "
204+
f"were found in store {store_path.store!r} at path {store_path.path!r}."
205205
)
206206
raise ArrayNotFoundError(msg)
207207
# set zarr_format based on which keys were found

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def parse_node_type(data: object) -> NodeType:
9494
"""Parse the node_type field from metadata."""
9595
if data in get_args(NodeType):
9696
return cast(NodeType, data)
97-
msg = (f"Invalid node_type. Expected 'array' or 'group'. Got {data!r}.",)
97+
msg = f"Invalid node_type. Expected 'array' or 'group'. Got {data!r}."
9898
raise ValueError(msg)
9999

100100

src/zarr/core/metadata/v3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@
5555
def parse_zarr_format(data: object) -> Literal[3]:
5656
if data == 3:
5757
return 3
58-
msg = f"Invalid value for zarr_format. Expected 3. Got {data!r}."
59-
raise MetadataValidationError(msg)
58+
msg = f"Invalid zarr_format. Expected 3. Got {data!r}."
59+
raise ValueError(msg)
6060

6161

6262
def parse_node_type_array(data: object) -> Literal["array"]:
6363
if data == "array":
6464
return "array"
65-
msg = f"Invalid value for node_type. Expected 'array'. Got {data!r}."
66-
raise NodeTypeValidationError(msg)
65+
msg = f"Invalid node_type. Expected 'array'. Got {data!r}."
66+
raise ValueError(msg)
6767

6868

6969
def parse_codecs(data: object) -> tuple[Codec, ...]:

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ async def test_metadata_validation_error() -> None:
11121112
)
11131113
def test_open_array_with_mode_r_plus(store: Store) -> None:
11141114
# 'r+' means read/write (must exist)
1115-
msg = "Neither zarr.json (Zarr format 3) nor .zarray (Zarr format 2) metadata objects exist"
1115+
msg = "Neither Zarr V3 nor Zarr V2 array metadata documents were found"
11161116
with pytest.raises(ArrayNotFoundError, match=re.escape(msg)):
11171117
zarr.open_array(store=store, mode="r+")
11181118
zarr.ones(store=store, shape=(3, 3))

tests/test_metadata/test_v3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
@pytest.mark.parametrize("data", [None, 1, 2, 4, 5, "3"])
6363
def test_parse_zarr_format_invalid(data: Any) -> None:
6464
with pytest.raises(
65-
ValueError, match=f"Invalid value for 'zarr_format'. Expected '3'. Got '{data}'."
65+
ValueError, match=f"Invalid value for zarr_format. Expected 3. Got {data!r}."
6666
):
6767
parse_zarr_format(data)
6868

@@ -79,16 +79,16 @@ def test_parse_node_type_valid() -> None:
7979
@pytest.mark.parametrize("node_type", [None, 2, "other"])
8080
def test_parse_node_type_invalid(node_type: Any) -> None:
8181
with pytest.raises(
82-
MetadataValidationError,
83-
match=f"Invalid value for node_type. Expected 'array' or 'group'. Got {node_type!r}.",
82+
ValueError,
83+
match=f"Invalid node_type. Expected 'array' or 'group'. Got {node_type!r}.",
8484
):
8585
parse_node_type(node_type)
8686

8787

8888
@pytest.mark.parametrize("data", [None, "group"])
8989
def test_parse_node_type_array_invalid(data: Any) -> None:
9090
with pytest.raises(
91-
ValueError, match=f"Invalid value for node_type. Expected 'array'. Got {data!r}."
91+
ValueError, match=f"Invalid node_type. Expected 'array'. Got {data!r}."
9292
):
9393
parse_node_type_array(data)
9494

0 commit comments

Comments
 (0)