Skip to content

Commit 18afac9

Browse files
committed
Add Zarr version to gropu/array not found error messages
1 parent c06923d commit 18afac9

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/zarr/api/asynchronous.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,10 @@ async def open_group(
877877
overwrite=overwrite,
878878
attributes=attributes,
879879
)
880-
msg = f"No group found in store {store!r} at path {store_path.path!r}"
880+
if zarr_format is not None:
881+
msg = f"No Zarr {zarr_format} group found in store {store!r} at path {store_path.path!r}"
882+
else:
883+
msg = f"No Zarr group found in store {store!r} at path {store_path.path!r}"
881884
raise GroupNotFoundError(msg)
882885

883886

@@ -1290,7 +1293,10 @@ async def open_array(
12901293
overwrite=overwrite,
12911294
**kwargs,
12921295
)
1293-
msg = f"No array found in store {store_path.store} at path {store_path.path}"
1296+
if zarr_format is not None:
1297+
msg = f"No Zarr {zarr_format} array found in store {store_path.store} at path {store_path.path}"
1298+
else:
1299+
msg = f"No Zarr array found in store {store_path.store} at path {store_path.path}"
12941300
raise ArrayNotFoundError(msg) from err
12951301

12961302

tests/test_api.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from zarr.core.buffer import NDArrayLike
4646
from zarr.errors import (
4747
ArrayNotFoundError,
48+
GroupNotFoundError,
4849
MetadataValidationError,
4950
ZarrDeprecationWarning,
5051
ZarrUserWarning,
@@ -1547,3 +1548,33 @@ def test_unimplemented_kwarg_warnings(kwarg_name: str) -> None:
15471548
kwargs = {kwarg_name: 1}
15481549
with pytest.warns(RuntimeWarning, match=".* is not yet implemented"):
15491550
zarr.create(shape=(1,), **kwargs) # type: ignore[arg-type]
1551+
1552+
1553+
def test_specific_fmt_error_message_group() -> None:
1554+
store = zarr.storage.MemoryStore()
1555+
# Create a group
1556+
zarr.create_group(store=store, path="my_group", zarr_format=3)
1557+
# Check that the new group exists
1558+
zarr.open_group(store=store, path="my_group", mode="r", zarr_format=3)
1559+
# Check error message when opening with wrong Zarr format
1560+
with pytest.raises(GroupNotFoundError, match="No Zarr 2 group found"):
1561+
zarr.open_group(store=store, path="my_group", mode="r", zarr_format=2)
1562+
1563+
1564+
def test_specific_fmt_error_message_array() -> None:
1565+
store = zarr.storage.MemoryStore()
1566+
# Create an array
1567+
zarr.create_array(
1568+
store=store,
1569+
zarr_format=3,
1570+
data=np.array(
1571+
[
1572+
1,
1573+
]
1574+
),
1575+
)
1576+
# Check that the new array exists
1577+
zarr.open_array(store=store, mode="r", zarr_format=3)
1578+
# Check error message when opening with wrong Zarr format
1579+
with pytest.raises(ArrayNotFoundError, match="No Zarr 2 array found"):
1580+
zarr.open_array(store=store, mode="r", zarr_format=2)

0 commit comments

Comments
 (0)