Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/uproot_browser/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def plot(tree: Any) -> None:
raise RuntimeError(msg)


@plot.register
def plot_branch(tree: uproot.TBranch) -> None:
# Simpler in Python 3.11+
@plot.register(uproot.TBranch)
def plot_branch(tree: uproot.TBranch | uproot.models.RNTuple.RField) -> None:
"""
Plot a single tree branch.
"""
Expand All @@ -69,6 +70,10 @@ def plot_branch(tree: uproot.TBranch) -> None:
plt.title(make_hist_title(tree, histogram))


if hasattr(uproot.models, "RNTuple") and hasattr(uproot.models.RNTuple, "RField"):
plot.register(uproot.models.RNTuple.RField)(plot_branch) # type: ignore[no-untyped-call]


@plot.register
def plot_hist(tree: uproot.behaviors.TH1.Histogram) -> None:
"""
Expand Down
22 changes: 20 additions & 2 deletions src/uproot_browser/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def _(item: uproot.behaviors.TBranch.HasBranches) -> bool:
return len(item.branches) > 0


if hasattr(uproot.behaviors, "RNTuple") and hasattr(
uproot.behaviors.RNTuple, "HasFields"
):

@is_dir.register
def _(item: uproot.behaviors.RNTuple.HasFields) -> bool:
return len(item.keys()) > 0


def get_children(item: Mapping[str, Any]) -> set[str]:
return {
key.split(";")[0]
Expand Down Expand Up @@ -152,8 +161,11 @@ def _process_item_tfile(
)


@process_item.register
def _process_item_ttree(uproot_object: uproot.TTree) -> MetaDict:
# Python 3.11 can just use `|` directly for register
@process_item.register(uproot.TTree)
def _process_item_ttree(
uproot_object: uproot.TTree | uproot.behaviors.RNTuple.RNTuple,
) -> MetaDict:
"""
Given an tree, return a rich.tree.Tree output.
"""
Expand All @@ -169,6 +181,12 @@ def _process_item_ttree(uproot_object: uproot.TTree) -> MetaDict:
)


if hasattr(uproot.behaviors, "RNTuple") and hasattr(
uproot.behaviors.RNTuple, "HasFields"
):
process_item.register(uproot.behaviors.RNTuple.RNTuple)(_process_item_ttree) # type: ignore[no-untyped-call]


@process_item.register
def _process_item_tbranch(uproot_object: uproot.TBranch) -> MetaDict:
"""
Expand Down
Loading