Skip to content

Commit af55fcf

Browse files
authored
Add a GroupNotFoundError (#3066)
* Add a GroupNotFoundError * Fixup tests * Add changelog entries * Remove inheritance change
1 parent feb4aa2 commit af55fcf

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

changes/3066.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `~zarr.errors.GroupNotFoundError`, which is raised when attempting to open a group that does not exist.

src/zarr/api/asynchronous.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040
from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
4141
from zarr.core.metadata.v2 import _default_compressor, _default_filters
42-
from zarr.errors import NodeTypeValidationError
42+
from zarr.errors import GroupNotFoundError, NodeTypeValidationError
4343
from zarr.storage._common import make_store_path
4444

4545
if TYPE_CHECKING:
@@ -836,7 +836,7 @@ async def open_group(
836836
overwrite=overwrite,
837837
attributes=attributes,
838838
)
839-
raise FileNotFoundError(f"Unable to find group: {store_path}")
839+
raise GroupNotFoundError(store, store_path.path)
840840

841841

842842
async def create(

src/zarr/errors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ def __init__(self, *args: Any) -> None:
2121
super().__init__(self._msg.format(*args))
2222

2323

24+
class GroupNotFoundError(BaseZarrError, FileNotFoundError):
25+
"""
26+
Raised when a group isn't found at a certain path.
27+
"""
28+
29+
_msg = "No group found in store {!r} at path {!r}"
30+
31+
2432
class ContainsGroupError(BaseZarrError):
2533
"""Raised when a group already exists at a certain path."""
2634

tests/test_metadata/test_v3.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
parse_fill_value,
2121
parse_zarr_format,
2222
)
23-
from zarr.errors import MetadataValidationError
23+
from zarr.errors import MetadataValidationError, NodeTypeValidationError
2424

2525
if TYPE_CHECKING:
2626
from collections.abc import Sequence
@@ -62,7 +62,8 @@
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+
MetadataValidationError,
66+
match=f"Invalid value for 'zarr_format'. Expected '3'. Got '{data}'.",
6667
):
6768
parse_zarr_format(data)
6869

@@ -88,7 +89,8 @@ def test_parse_node_type_invalid(node_type: Any) -> None:
8889
@pytest.mark.parametrize("data", [None, "group"])
8990
def test_parse_node_type_array_invalid(data: Any) -> None:
9091
with pytest.raises(
91-
ValueError, match=f"Invalid value for 'node_type'. Expected 'array'. Got '{data}'."
92+
NodeTypeValidationError,
93+
match=f"Invalid value for 'node_type'. Expected 'array'. Got '{data}'.",
9294
):
9395
parse_node_type_array(data)
9496

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy