Skip to content

Commit 731e3ba

Browse files
authored
fix: support accessing RNTuple fields by full path (#1466)
* Support accessing RNTuple fields by full path * Added tests * Fixed other error message
1 parent df72db9 commit 731e3ba

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/uproot/reading.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ def __getitem__(self, where):
20882088
raise uproot.KeyInFileError(
20892089
where,
20902090
because=repr(head)
2091-
+ " is not a TDirectory, TTree, or TBranch",
2091+
+ " is not a TDirectory, TTree, TBranch, RNTuple, or RField",
20922092
keys=[key.fName for key in last._keys],
20932093
file_path=self._file.file_path,
20942094
)
@@ -2098,14 +2098,20 @@ def __getitem__(self, where):
20982098
last = step
20992099
step = step[item]
21002100

2101-
elif isinstance(step, uproot.behaviors.TBranch.HasBranches):
2101+
elif isinstance(
2102+
step,
2103+
(
2104+
uproot.behaviors.TBranch.HasBranches,
2105+
uproot.behaviors.RNTuple.HasFields,
2106+
),
2107+
):
21022108
return step["/".join(items[i:])]
21032109

21042110
else:
21052111
raise uproot.KeyInFileError(
21062112
where,
21072113
because="/".join(items[:i])
2108-
+ " is not a TDirectory, TTree, or TBranch",
2114+
+ " is not a TDirectory, TTree, TBranch, RNTuple, or RField",
21092115
keys=[key.fName for key in last._keys],
21102116
file_path=self._file.file_path,
21112117
)

tests/test_1250_rntuple_improvements.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ def test_field_class():
1212
obj = f["ntuple"]
1313
my_struct = obj["my_struct"]
1414
assert len(my_struct) == 2
15+
assert my_struct is f["ntuple/my_struct"]
16+
assert my_struct is f["ntuple"]["my_struct"]
1517

1618
sub_struct = my_struct["sub_struct"]
1719
assert len(my_struct) == 2
20+
assert sub_struct is f["ntuple/my_struct/sub_struct"]
21+
assert sub_struct is f["ntuple"]["my_struct"]["sub_struct"]
1822

1923
sub_sub_struct = sub_struct["sub_sub_struct"]
2024
assert len(sub_sub_struct) == 2
25+
assert sub_sub_struct is f["ntuple/my_struct/sub_struct/sub_sub_struct"]
26+
assert (
27+
sub_sub_struct is f["ntuple"]["my_struct"]["sub_struct"]["sub_sub_struct"]
28+
)
2129

2230
v = sub_sub_struct["v"]
2331
assert len(v) == 1

0 commit comments

Comments
 (0)