Skip to content

Commit 3be878d

Browse files
committed
keyerror -> filenotfounderror, fixup
1 parent 6b56342 commit 3be878d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/zarr/core/group.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ async def getitem(
693693
# Consolidated metadata lets us avoid some I/O operations so try that first.
694694
if self.metadata.consolidated_metadata is not None:
695695
return self._getitem_consolidated(store_path, key, prefix=self.name)
696-
elif self.metadata.zarr_format == 3:
697-
return await _read_node_v3(store=self.store, path=store_path.path)
698-
elif self.metadata.zarr_format == 2:
699-
return await _read_node_v2(store=self.store, path=store_path.path)
700-
else:
701-
raise ValueError(f"unexpected zarr_format: {self.metadata.zarr_format}")
696+
try:
697+
return await _read_node_a(
698+
store=store_path.store, path=store_path.path, zarr_format=self.metadata.zarr_format
699+
)
700+
except FileNotFoundError as e:
701+
raise KeyError(key) from e
702702

703703
def _getitem_consolidated(
704704
self, store_path: StorePath, key: str, prefix: str
@@ -3419,7 +3419,7 @@ async def _read_metadata_v2(store: Store, path: str) -> ArrayV2Metadata | GroupM
34193419
"""
34203420
Given a store_path, return ArrayV2Metadata or GroupMetadata defined by the metadata
34213421
document stored at store_path.path / (.zgroup | .zarray). If no such document is found,
3422-
raise a KeyError.
3422+
raise a FileNotFoundError.
34233423
"""
34243424
# TODO: consider first fetching array metadata, and only fetching group metadata when we don't
34253425
# find an array

tests/test_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ async def test_create_hierarchy(
15451545
)
15461546
assert extra_group.metadata.attributes == {"path": "group/extra"}
15471547
else:
1548-
with pytest.raises(KeyError):
1548+
with pytest.raises(FileNotFoundError):
15491549
read_node(store=store, path=_join_paths([path, "group/extra"]), zarr_format=zarr_format)
15501550
assert expected_meta == {k: v.metadata for k, v in observed_nodes.items()}
15511551

0 commit comments

Comments
 (0)