Skip to content

Commit

Permalink
fix: interpretation for arrays of non-numerical objects issue 880 par…
Browse files Browse the repository at this point in the history
…t2 (#911)

* fix: interpretation for arrays of non-numerical objects issue 880 part2

* style: pre-commit fixes

* Change name of test file to match PR nr.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ioanaif and pre-commit-ci[bot] authored Jun 30, 2023
1 parent e0cbfec commit fcb7b14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/uproot/interpretation/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,23 @@ def interpretation_of(branch, context, simplify=True):
while isinstance(model_cls, uproot.containers.AsPointer):
model_cls = model_cls.pointee

if branch._streamer_isTClonesArray:
if isinstance(branch.streamer, uproot.streamers.Model_TStreamerObject):
if dims != () or branch._streamer_isTClonesArray:
if (
isinstance(branch.streamer, uproot.streamers.Model_TStreamerObject)
or not branch._streamer_isTClonesArray
):
model_cls = uproot.containers.AsArray(False, False, model_cls, dims)
else:
if hasattr(model_cls, "header"):
model_cls._header = False
model_cls = uproot.containers.AsArray(True, False, model_cls, dims)

out = uproot.interpretation.objects.AsObjects(model_cls, branch)
if dims != () and not branch._streamer_isTClonesArray:
out = uproot.interpretation.objects.AsObjects(model_cls, branch)
out._forth = False
else:
out = uproot.interpretation.objects.AsObjects(model_cls, branch)

if simplify:
return out.simplify()
else:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_0911-fix_interp_array_non_numerical_objs_issue_880.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import uproot
import skhep_testdata


def test_fix_interpretation_for_arrays_of_nonnumerical_objects_issue_880_p2():
with uproot.open(skhep_testdata.data_path("uproot-issue-880.root")) as file:
branch = file["Z/Event/Cluster[6]"]
array = branch.array(library="ak")
interp = uproot.interpretation.identify.interpretation_of(
branch, {}, False
) # AsObjects(AsArray(False, False, Model_zCluster, (6,)))

assert len(array) == 116
assert len(array[0][0]) == 6 # all 6 cluster can now be accessed

0 comments on commit fcb7b14

Please sign in to comment.