Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Group.tree method #2433

Merged
merged 5 commits into from
Nov 13, 2024
Merged

Conversation

TomAugspurger
Copy link
Contributor

@TomAugspurger TomAugspurger commented Oct 23, 2024

Adds a Group.tree method for pretty printing a hierarchy.

Screenshot 2024-10-24 at 8 05 59 AM

For now the old expand keyword, which I think controlled whether the tree was expanded by default in the HTML output, is not implemented.

We have one design choice to make: should .tree return an object with a custom __repr__, or should it return the string itself? My preference, implemented here, is returning the object. That makes it easier to pipe into other applications other than the Python REPL. The cost is a bit more expansion of the public API.

Closes #2406

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@TomAugspurger TomAugspurger marked this pull request as ready for review October 24, 2024 13:43
@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented Nov 8, 2024

There was a notebooks/repr_tree.ipynb notebook that I just ran through. This PR does not implement

  • A plain ASCII tree repr with print(bytes(g1.tree()).decode()). We kind of get that for free through rich, which will automatically detect whether the console being rendered to supports unicode or just ASCII. We won't have an API for doing that (we can probably document how to configure rich to get out an ascii repr if someone really wants that)
  • An interactive HTML repr (I think for collapsing nodes). I've toyed around with the idea of a textual-based TUI for Zarr groups that would be a better spot for this kind of interactive explorer IMO.

If we're OK with those limitations then this should be good to go.

Copy link
Member

@jhamman jhamman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @TomAugspurger!

async def group_tree_async(group: AsyncGroup, max_depth: int | None = None) -> TreeRepr:
tree = rich.tree.Tree(label=f"[bold]{group.name}[/bold]")
nodes = {"": tree}
members = sorted([x async for x in group.members(max_depth=max_depth)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @d-v-b who is looking at making this faster 🚀

A simple object with a tree-like repr for the Zarr Group.

Note that this object and it's implementation isn't considered part
of Zarr's public API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jhamman jhamman merged commit 89e1d4f into zarr-developers:main Nov 13, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v3] Implement Group.tree
3 participants