Skip to content

Commit

Permalink
fix: awkward_form breadcrumbs class issue 880 (#886)
Browse files Browse the repository at this point in the history
* fix: awkward_form breadcrumbs class issue 879

* Add local file for testing before using scikit-hep-testdata.

* style: pre-commit fixes

* Fix test imports.

* Get test data from skhep_testdata.

* Make a copy of the breadcrumbs before changing them.

---------

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 May 16, 2023
1 parent 1a295a7 commit 366e3dc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/uproot/behaviors/TBranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ def _awkward_check(self, interpretation):
{}
instead, try library="np" instead of library="ak" or globally set uproot.default_library
instead, try library="np" rather than library="ak" or globally set uproot.default_library
in file {}
in object {}""".format(
Expand Down
2 changes: 2 additions & 0 deletions src/uproot/models/TAtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -679,6 +680,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down
3 changes: 3 additions & 0 deletions src/uproot/models/TGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -455,6 +456,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -666,6 +668,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down
22 changes: 22 additions & 0 deletions src/uproot/models/TH.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -814,6 +815,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -1119,6 +1121,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -1328,6 +1331,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -1517,6 +1521,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -1679,6 +1684,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -1836,6 +1842,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -1993,6 +2000,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -2155,6 +2163,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -2317,6 +2326,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -2480,6 +2490,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -2638,6 +2649,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -2801,6 +2813,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -2964,6 +2977,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -3127,6 +3141,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -3291,6 +3306,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -3450,6 +3466,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -3614,6 +3631,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -3778,6 +3796,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -3978,6 +3997,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -4217,6 +4237,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down Expand Up @@ -4458,6 +4479,7 @@ def awkward_form(cls, file, context):
raise uproot.interpretation.objects.CannotBeAwkward(
"classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded"
)
context = context.copy()
context["breadcrumbs"] = context["breadcrumbs"] + (cls,)
contents = {}
if context["header"]:
Expand Down
1 change: 1 addition & 0 deletions src/uproot/streamers.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def class_code(self):
" from awkward.forms import NumpyForm, ListOffsetForm, RegularForm, RecordForm",
" if cls in context['breadcrumbs']:",
" raise uproot.interpretation.objects.CannotBeAwkward('classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded')",
" context = context.copy()",
" context['breadcrumbs'] = context['breadcrumbs'] + (cls,)",
" contents = {}",
" if context['header']:",
Expand Down
10 changes: 10 additions & 0 deletions tests/test_0886-fix-awkward-form-breadcrumbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import uproot
import skhep_testdata


def test_fix_awkward_form_breadcrumbs():
file = uproot.open(skhep_testdata.data_path("uproot-issue-880.root"))
tree = file["Z"]
assert tree.num_entries == 116

0 comments on commit 366e3dc

Please sign in to comment.