@@ -406,9 +406,16 @@ def groups(self):
406
406
cache_attrs = self .attrs .cache ,
407
407
synchronizer = self ._synchronizer )
408
408
409
- def array_keys (self ):
409
+ def array_keys (self , recurse = False ):
410
410
"""Return an iterator over member names for arrays only.
411
411
412
+ Parameters
413
+ ----------
414
+ recurse : recurse, optional
415
+ Option to return member names for all arrays, even from groups
416
+ below the current one. If False, only member names for arrays in
417
+ the current group will be returned. Default value is False.
418
+
412
419
Examples
413
420
--------
414
421
>>> import zarr
@@ -421,14 +428,20 @@ def array_keys(self):
421
428
['baz', 'quux']
422
429
423
430
"""
424
- for key in sorted (listdir (self ._store , self ._path )):
425
- path = self ._key_prefix + key
426
- if contains_array (self ._store , path ):
427
- yield key
431
+ return self ._array_iter (keys_only = True ,
432
+ method = 'array_keys' ,
433
+ recurse = recurse )
428
434
429
- def arrays (self ):
435
+ def arrays (self , recurse = False ):
430
436
"""Return an iterator over (name, value) pairs for arrays only.
431
437
438
+ Parameters
439
+ ----------
440
+ recurse : recurse, optional
441
+ Option to return (name, value) pairs for all arrays, even from groups
442
+ below the current one. If False, only (name, value) pairs for arrays in
443
+ the current group will be returned. Default value is False.
444
+
432
445
Examples
433
446
--------
434
447
>>> import zarr
@@ -443,13 +456,19 @@ def arrays(self):
443
456
quux <class 'zarr.core.Array'>
444
457
445
458
"""
459
+ return self ._array_iter (keys_only = False ,
460
+ method = 'arrays' ,
461
+ recurse = recurse )
462
+
463
+ def _array_iter (self , keys_only , method , recurse ):
446
464
for key in sorted (listdir (self ._store , self ._path )):
447
465
path = self ._key_prefix + key
448
466
if contains_array (self ._store , path ):
449
- yield key , Array (self ._store , path = path , read_only = self ._read_only ,
450
- chunk_store = self ._chunk_store ,
451
- cache_attrs = self .attrs .cache ,
452
- synchronizer = self ._synchronizer )
467
+ yield key if keys_only else (key , self [key ])
468
+ elif recurse and contains_group (self ._store , path ):
469
+ group = self [key ]
470
+ for i in getattr (group , method )(recurse = recurse ):
471
+ yield i
453
472
454
473
def visitvalues (self , func ):
455
474
"""Run ``func`` on each object.
0 commit comments