Skip to content

Commit 32e3de6

Browse files
committed
Handle max_depth==None
1 parent ebe2670 commit 32e3de6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/zarr/core/group.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,13 @@ 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([x for x in self.metadata.consolidated_metadata.flattened_metadata if x.count("/") <= max_depth])
1310+
if max_depth is not None and max_depth < 0:
1311+
raise ValueError(f"max_depth must be None or >= 0. Got '{max_depth}' instead")
1312+
if max_depth is None:
1313+
return len(self.metadata.consolidated_metadata.flattened_metadata)
1314+
else:
1315+
return len([x for x in self.metadata.consolidated_metadata.flattened_metadata if x.count("/") <= max_depth])
1316+
13111317
# TODO: consider using aioitertools.builtins.sum for this
13121318
# return await aioitertools.builtins.sum((1 async for _ in self.members()), start=0)
13131319
n = 0

0 commit comments

Comments
 (0)