Skip to content

Commit 143954a

Browse files
committed
Add visitkeys as an alias to visit.
1 parent ab37a6d commit 143954a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

docs/api/hierarchy.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Groups (``zarr.hierarchy``)
1616
.. automethod:: array_keys
1717
.. automethod:: arrays
1818
.. automethod:: visit
19+
.. automethod:: visitkeys
1920
.. automethod:: visitvalues
2021
.. automethod:: visititems
2122
.. automethod:: create_group

zarr/hierarchy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Group(MutableMapping):
5757
array_keys
5858
arrays
5959
visit
60+
visitkeys
6061
visitvalues
6162
visititems
6263
create_group
@@ -497,6 +498,12 @@ def visit(self, func):
497498
base_len = len(self.name)
498499
return self.visitvalues(lambda o: func(o.name[base_len:].lstrip("/")))
499500

501+
def visitkeys(self, func):
502+
"""An alias for :py:meth:`~Group.visit`.
503+
"""
504+
505+
return self.visit(func)
506+
500507
def visititems(self, func):
501508
"""Run ``func`` on each object's path and the object itself.
502509

zarr/tests/test_hierarchy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,24 @@ def visitor4(name, obj):
521521
"baz",
522522
], items)
523523

524+
del items[:]
525+
g1.visitkeys(visitor3)
526+
eq([
527+
"a",
528+
"a/b",
529+
"a/b/c",
530+
"foo",
531+
"foo/bar",
532+
"foo/baz",
533+
], items)
534+
535+
del items[:]
536+
g1["foo"].visitkeys(visitor3)
537+
eq([
538+
"bar",
539+
"baz",
540+
], items)
541+
524542
del items[:]
525543
g1.visititems(visitor3)
526544
eq([
@@ -563,9 +581,11 @@ def visitor1(val, *args):
563581
return True # pragma: no cover
564582

565583
eq(None, g1.visit(visitor0))
584+
eq(None, g1.visitkeys(visitor0))
566585
eq(None, g1.visitvalues(visitor0))
567586
eq(None, g1.visititems(visitor0))
568587
eq(True, g1.visit(visitor1))
588+
eq(True, g1.visitkeys(visitor1))
569589
eq(True, g1.visitvalues(visitor1))
570590
eq(True, g1.visititems(visitor1))
571591

0 commit comments

Comments
 (0)