Skip to content

Commit 6b9ea28

Browse files
committed
fix: conditional RNtuple
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 3aa67d7 commit 6b9ea28

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/uproot_browser/plot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def plot(tree: Any) -> None:
5252

5353
# Simpler in Python 3.11+
5454
@plot.register(uproot.TBranch)
55-
@plot.register(uproot.models.RNTuple.RField)
5655
def plot_branch(tree: uproot.TBranch | uproot.models.RNTuple.RField) -> None:
5756
"""
5857
Plot a single tree branch.
@@ -71,6 +70,10 @@ def plot_branch(tree: uproot.TBranch | uproot.models.RNTuple.RField) -> None:
7170
plt.title(make_hist_title(tree, histogram))
7271

7372

73+
if hasattr(uproot.models, "RNTuple") and hasattr(uproot.models.RNTuple, "RField"):
74+
plot.register(uproot.models.RNTuple.RField)(plot_branch) # type: ignore[no-untyped-call]
75+
76+
7477
@plot.register
7578
def plot_hist(tree: uproot.behaviors.TH1.Histogram) -> None:
7679
"""

src/uproot_browser/tree.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ def _(item: uproot.behaviors.TBranch.HasBranches) -> bool:
5757
return len(item.branches) > 0
5858

5959

60-
@is_dir.register
61-
def _(item: uproot.behaviors.RNTuple.HasFields) -> bool:
62-
return len(item.keys()) > 0
60+
if hasattr(uproot.behaviors, "RNTuple") and hasattr(
61+
uproot.behaviors.RNTuple, "HasFields"
62+
):
63+
64+
@is_dir.register
65+
def _(item: uproot.behaviors.RNTuple.HasFields) -> bool:
66+
return len(item.keys()) > 0
6367

6468

6569
def get_children(item: Mapping[str, Any]) -> set[str]:
@@ -159,7 +163,6 @@ def _process_item_tfile(
159163

160164
# Python 3.11 can just use `|` directly for register
161165
@process_item.register(uproot.TTree)
162-
@process_item.register(uproot.behaviors.RNTuple.RNTuple)
163166
def _process_item_ttree(
164167
uproot_object: uproot.TTree | uproot.behaviors.RNTuple.RNTuple,
165168
) -> MetaDict:
@@ -178,6 +181,12 @@ def _process_item_ttree(
178181
)
179182

180183

184+
if hasattr(uproot.behaviors, "RNTuple") and hasattr(
185+
uproot.behaviors.RNTuple, "HasFields"
186+
):
187+
process_item.register(uproot.behaviors.RNTuple.RNTuple)(_process_item_ttree) # type: ignore[no-untyped-call]
188+
189+
181190
@process_item.register
182191
def _process_item_tbranch(uproot_object: uproot.TBranch) -> MetaDict:
183192
"""

0 commit comments

Comments
 (0)