Skip to content

Commit ebe2670

Browse files
committed
Fix incorrect Group.nmembers for consolidated metadata
1 parent b877f89 commit ebe2670

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ async def nmembers(
13071307
# check if we can use consolidated metadata, which requires that we have non-None
13081308
# consolidated metadata at all points in the hierarchy.
13091309
if self.metadata.consolidated_metadata is not None:
1310-
return len(self.metadata.consolidated_metadata.flattened_metadata)
1310+
return len([x for x in self.metadata.consolidated_metadata.flattened_metadata if x.count("/") <= max_depth])
13111311
# TODO: consider using aioitertools.builtins.sum for this
13121312
# return await aioitertools.builtins.sum((1 async for _ in self.members()), start=0)
13131313
n = 0

tests/test_group.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,13 @@ async def test_group_members_async(store: Store, consolidated_metadata: bool) ->
11181118
"consolidated_metadata",
11191119
None,
11201120
)
1121+
# test depth=0
1122+
nmembers = await group.nmembers(max_depth=0)
1123+
assert nmembers == 2
1124+
# test depth=1
1125+
nmembers = await group.nmembers(max_depth=1)
1126+
assert nmembers == 4
1127+
# test depth=None
11211128
all_children = sorted(
11221129
[x async for x in group.members(max_depth=None)], key=operator.itemgetter(0)
11231130
)

0 commit comments

Comments
 (0)