Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid redundant __contains__ #1739

Merged
merged 2 commits into from
Apr 4, 2024
Merged
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
13 changes: 10 additions & 3 deletions zarr/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from zarr.errors import (
ContainsArrayError,
ContainsGroupError,
ArrayNotFoundError,
GroupNotFoundError,
ReadOnlyError,
)
Expand Down Expand Up @@ -457,7 +458,7 @@ def __getitem__(self, item):

"""
path = self._item_path(item)
if contains_array(self._store, path):
try:
return Array(
self._store,
read_only=self._read_only,
Expand All @@ -468,7 +469,10 @@ def __getitem__(self, item):
zarr_version=self._version,
meta_array=self._meta_array,
)
elif contains_group(self._store, path, explicit_only=True):
except ArrayNotFoundError:
pass

try:
return Group(
self._store,
read_only=self._read_only,
Expand All @@ -479,7 +483,10 @@ def __getitem__(self, item):
zarr_version=self._version,
meta_array=self._meta_array,
)
elif self._version == 3:
except GroupNotFoundError:
pass

if self._version == 3:
implicit_group = meta_root + path + "/"
# non-empty folder in the metadata path implies an implicit group
if self._store.list_prefix(implicit_group):
Expand Down
Loading