@@ -1305,6 +1305,8 @@ async def nmembers(
1305
1305
async def members (
1306
1306
self ,
1307
1307
max_depth : int | None = 0 ,
1308
+ * ,
1309
+ use_consolidated_for_children : bool = True ,
1308
1310
) -> AsyncGenerator [
1309
1311
tuple [str , AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ] | AsyncGroup ],
1310
1312
None ,
@@ -1322,6 +1324,11 @@ async def members(
1322
1324
default, (``max_depth=0``) only immediate children are included. Set
1323
1325
``max_depth=None`` to include all nodes, and some positive integer
1324
1326
to consider children within that many levels of the root Group.
1327
+ use_consolidated_for_children : bool, default True
1328
+ Whether to use the consolidated metadata of child groups loaded
1329
+ from the store. Note that this only affects groups loaded from the
1330
+ store. If the current Group already has consolidated metadata, it
1331
+ will always be used.
1325
1332
1326
1333
Returns
1327
1334
-------
@@ -1332,7 +1339,9 @@ async def members(
1332
1339
"""
1333
1340
if max_depth is not None and max_depth < 0 :
1334
1341
raise ValueError (f"max_depth must be None or >= 0. Got '{ max_depth } ' instead" )
1335
- async for item in self ._members (max_depth = max_depth ):
1342
+ async for item in self ._members (
1343
+ max_depth = max_depth , use_consolidated_for_children = use_consolidated_for_children
1344
+ ):
1336
1345
yield item
1337
1346
1338
1347
def _members_consolidated (
@@ -1362,7 +1371,7 @@ def _members_consolidated(
1362
1371
yield from obj ._members_consolidated (new_depth , prefix = key )
1363
1372
1364
1373
async def _members (
1365
- self , max_depth : int | None
1374
+ self , max_depth : int | None , * , use_consolidated_for_children : bool = True
1366
1375
) -> AsyncGenerator [
1367
1376
tuple [str , AsyncArray [ArrayV3Metadata ] | AsyncArray [ArrayV2Metadata ] | AsyncGroup ], None
1368
1377
]:
@@ -1392,7 +1401,11 @@ async def _members(
1392
1401
# enforce a concurrency limit by passing a semaphore to all the recursive functions
1393
1402
semaphore = asyncio .Semaphore (config .get ("async.concurrency" ))
1394
1403
async for member in _iter_members_deep (
1395
- self , max_depth = max_depth , skip_keys = skip_keys , semaphore = semaphore
1404
+ self ,
1405
+ max_depth = max_depth ,
1406
+ skip_keys = skip_keys ,
1407
+ semaphore = semaphore ,
1408
+ use_consolidated_for_children = use_consolidated_for_children ,
1396
1409
):
1397
1410
yield member
1398
1411
@@ -2092,10 +2105,34 @@ def nmembers(self, max_depth: int | None = 0) -> int:
2092
2105
2093
2106
return self ._sync (self ._async_group .nmembers (max_depth = max_depth ))
2094
2107
2095
- def members (self , max_depth : int | None = 0 ) -> tuple [tuple [str , Array | Group ], ...]:
2108
+ def members (
2109
+ self , max_depth : int | None = 0 , * , use_consolidated_for_children : bool = True
2110
+ ) -> tuple [tuple [str , Array | Group ], ...]:
2096
2111
"""
2097
- Return the sub-arrays and sub-groups of this group as a tuple of (name, array | group)
2098
- pairs
2112
+ Returns an AsyncGenerator over the arrays and groups contained in this group.
2113
+ This method requires that `store_path.store` supports directory listing.
2114
+
2115
+ The results are not guaranteed to be ordered.
2116
+
2117
+ Parameters
2118
+ ----------
2119
+ max_depth : int, default 0
2120
+ The maximum number of levels of the hierarchy to include. By
2121
+ default, (``max_depth=0``) only immediate children are included. Set
2122
+ ``max_depth=None`` to include all nodes, and some positive integer
2123
+ to consider children within that many levels of the root Group.
2124
+ use_consolidated_for_children : bool, default True
2125
+ Whether to use the consolidated metadata of child groups loaded
2126
+ from the store. Note that this only affects groups loaded from the
2127
+ store. If the current Group already has consolidated metadata, it
2128
+ will always be used.
2129
+
2130
+ Returns
2131
+ -------
2132
+ path:
2133
+ A string giving the path to the target, relative to the Group ``self``.
2134
+ value: AsyncArray or AsyncGroup
2135
+ The AsyncArray or AsyncGroup that is a child of ``self``.
2099
2136
"""
2100
2137
_members = self ._sync_iter (self ._async_group .members (max_depth = max_depth ))
2101
2138
@@ -3329,6 +3366,7 @@ async def _iter_members_deep(
3329
3366
max_depth : int | None ,
3330
3367
skip_keys : tuple [str , ...],
3331
3368
semaphore : asyncio .Semaphore | None = None ,
3369
+ use_consolidated_for_children : bool = True ,
3332
3370
) -> AsyncGenerator [
3333
3371
tuple [str , AsyncArray [ArrayV3Metadata ] | AsyncArray [ArrayV2Metadata ] | AsyncGroup ], None
3334
3372
]:
@@ -3346,6 +3384,11 @@ async def _iter_members_deep(
3346
3384
A tuple of keys to skip when iterating over the possible members of the group.
3347
3385
semaphore : asyncio.Semaphore | None
3348
3386
An optional semaphore to use for concurrency control.
3387
+ use_consolidated_for_children : bool, default True
3388
+ Whether to use the consolidated metadata of child groups loaded
3389
+ from the store. Note that this only affects groups loaded from the
3390
+ store. If the current Group already has consolidated metadata, it
3391
+ will always be used.
3349
3392
3350
3393
Yields
3351
3394
------
@@ -3360,8 +3403,19 @@ async def _iter_members_deep(
3360
3403
else :
3361
3404
new_depth = max_depth - 1
3362
3405
async for name , node in _iter_members (group , skip_keys = skip_keys , semaphore = semaphore ):
3406
+ is_group = isinstance (node , AsyncGroup )
3407
+ if (
3408
+ is_group
3409
+ and not use_consolidated_for_children
3410
+ and node .metadata .consolidated_metadata is not None # type: ignore [union-attr]
3411
+ ):
3412
+ node = cast ("AsyncGroup" , node )
3413
+ # We've decided not to trust consolidated metadata at this point, because we're
3414
+ # reconsolidating the metadata, for example.
3415
+ node = replace (node , metadata = replace (node .metadata , consolidated_metadata = None ))
3363
3416
yield name , node
3364
- if isinstance (node , AsyncGroup ) and do_recursion :
3417
+ if is_group and do_recursion :
3418
+ node = cast ("AsyncGroup" , node )
3365
3419
to_recurse [name ] = _iter_members_deep (
3366
3420
node , max_depth = new_depth , skip_keys = skip_keys , semaphore = semaphore
3367
3421
)
0 commit comments