Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,10 @@ async def open_group(
overwrite=overwrite,
attributes=attributes,
)
msg = f"No group found in store {store!r} at path {store_path.path!r}"
if zarr_format is not None:
msg = f"No Zarr {zarr_format} group found in store {store!r} at path {store_path.path!r}"
else:
msg = f"No Zarr group found in store {store!r} at path {store_path.path!r}"
raise GroupNotFoundError(msg)


Expand Down Expand Up @@ -1290,7 +1293,10 @@ async def open_array(
overwrite=overwrite,
**kwargs,
)
msg = f"No array found in store {store_path.store} at path {store_path.path}"
if zarr_format is not None:
msg = f"No Zarr {zarr_format} array found in store {store_path.store} at path {store_path.path}"
else:
msg = f"No Zarr array found in store {store_path.store} at path {store_path.path}"
raise ArrayNotFoundError(msg) from err


Expand Down
31 changes: 31 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from zarr.core.buffer import NDArrayLike
from zarr.errors import (
ArrayNotFoundError,
GroupNotFoundError,
MetadataValidationError,
ZarrDeprecationWarning,
ZarrUserWarning,
Expand Down Expand Up @@ -1547,3 +1548,33 @@ def test_unimplemented_kwarg_warnings(kwarg_name: str) -> None:
kwargs = {kwarg_name: 1}
with pytest.warns(RuntimeWarning, match=".* is not yet implemented"):
zarr.create(shape=(1,), **kwargs) # type: ignore[arg-type]


def test_specific_fmt_error_message_group() -> None:
store = zarr.storage.MemoryStore()
# Create a group
zarr.create_group(store=store, path="my_group", zarr_format=3)
# Check that the new group exists
zarr.open_group(store=store, path="my_group", mode="r", zarr_format=3)
# Check error message when opening with wrong Zarr format
with pytest.raises(GroupNotFoundError, match="No Zarr 2 group found"):
zarr.open_group(store=store, path="my_group", mode="r", zarr_format=2)


def test_specific_fmt_error_message_array() -> None:
store = zarr.storage.MemoryStore()
# Create an array
zarr.create_array(
store=store,
zarr_format=3,
data=np.array(
[
1,
]
),
)
# Check that the new array exists
zarr.open_array(store=store, mode="r", zarr_format=3)
# Check error message when opening with wrong Zarr format
with pytest.raises(ArrayNotFoundError, match="No Zarr 2 array found"):
zarr.open_array(store=store, mode="r", zarr_format=2)