Skip to content

Commit

Permalink
fastpath _array_iter for array_keys (zarr-developers#1149)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Moore <[email protected]>
  • Loading branch information
jhamman and joshmoore authored Nov 2, 2022
1 parent 5b9f2ef commit 8e6fe11
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions zarr/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,17 +638,19 @@ def _array_iter(self, keys_only, method, recurse):
else:
dir_name = meta_root + self._path
array_sfx = '.array' + self._metadata_key_suffix
group_sfx = '.group' + self._metadata_key_suffix

for key in sorted(listdir(self._store, dir_name)):
if key.endswith(array_sfx):
key = key[:-len(array_sfx)]
_key = key.rstrip("/")
yield _key if keys_only else (_key, self[key])

path = self._key_prefix + key
assert not path.startswith("meta/")
if key.endswith('.group' + self._metadata_key_suffix):
if key.endswith(group_sfx):
# skip group metadata keys
continue
if contains_array(self._store, path):
_key = key.rstrip("/")
yield _key if keys_only else (_key, self[key])
elif recurse and contains_group(self._store, path):
group = self[key]
yield from getattr(group, method)(recurse=recurse)
Expand Down

0 comments on commit 8e6fe11

Please sign in to comment.