Skip to content

Commit 039c091

Browse files
committed
implement / deprecate zarr.tree
1 parent fd688c4 commit 039c091

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/zarr/api/asynchronous.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,33 @@ async def save_group(
493493
await asyncio.gather(*aws)
494494

495495

496-
async def tree(*args: Any, **kwargs: Any) -> None:
497-
raise NotImplementedError
496+
async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None = None) -> Any:
497+
"""Provide a rich display of the hierarchy.
498+
499+
Parameters
500+
----------
501+
grp : Group
502+
Zarr or h5py group.
503+
expand : bool, optional
504+
Only relevant for HTML representation. If True, tree will be fully expanded.
505+
level : int, optional
506+
Maximum depth to descend into hierarchy.
507+
508+
Returns
509+
-------
510+
TreeRepr
511+
A pretty-printable object displaying the hierarchy.
512+
513+
.. deprecated:: 3.0.0
514+
`zarr.tree()` is deprecated and will be removed in a future release.
515+
Use `group.tree()` instead.
516+
"""
517+
warnings.warn(
518+
"zarr.tree() is deprecated and will be removed in a future release. Use group.tree() instead.",
519+
DeprecationWarning,
520+
stacklevel=2,
521+
)
522+
return await grp.tree(expand=expand, level=level)
498523

499524

500525
async def array(

src/zarr/api/synchronous.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def save_group(
155155
)
156156

157157

158-
def tree(*args: Any, **kwargs: Any) -> None:
159-
return sync(async_api.tree(*args, **kwargs))
158+
def tree(grp: Group, expand: bool | None = None, level: int | None = None) -> Any:
159+
return sync(async_api.tree(grp._async_group, expand=expand, level=level))
160160

161161

162162
# TODO: add type annotations for kwargs

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ async def tree(self, expand: bool | None = None, level: int | None = None) -> An
14491449
from zarr.core._tree import group_tree_async
14501450

14511451
if expand is not None:
1452-
raise NotImplementedError("'expanded' is not yet implemented.")
1452+
raise NotImplementedError("'expand' is not yet implemented.")
14531453
return await group_tree_async(self, max_depth=level)
14541454

14551455
async def empty(

0 commit comments

Comments
 (0)