You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reading root files which have been saved using the prescription #735 (comment) with column-filtering cannot be loaded by NanoEventsFactory using NanoAODSchema. Depending on the saved fields, the following exception is thrown:
TypeError: do not try to convert low-level layouts (Content subclasses) into NumPy arrays; put them in ak.highlevel.Array
The stack trace is quite deep and can be generated with the below example.
To Reproduce
Below is a small example script that demonstrates the behavior, where an exception is raised when trying to load the
importawkwardasakimportuprootfromcoffea.nanoeventsimportNanoEventsFactorydefis_rootcompat(a):
"""Is it a flat or 1-d jagged array?"""t=ak.type(a)
ifisinstance(t, ak.types.ArrayType):
ifisinstance(t.content, ak.types.NumpyType):
returnTrueifisinstance(t.content, ak.types.ListType) andisinstance(t.content.content, ak.types.NumpyType):
returnTruereturnFalsedefuproot_writeable(events):
"""Restrict to columns that uproot can write compactly"""out= {}
forbnameinevents.fields:
ifevents[bname].fields:
out[bname] =ak.zip({n:
ak.to_packed(ak.without_parameters(events[bname][n]))
forninevents[bname].fieldsifis_rootcompat(events[bname][n])},
)
else:
out[bname] =ak.to_packed(ak.without_parameters(events[bname]))
returnoutfilename="https://raw.githubusercontent.com/CoffeaTeam/coffea/master/tests/samples/nano_dy.root"events=NanoEventsFactory.from_root({filename: "Events"}, delayed=False).events()
defsaveAndLoad(events, columns):
filtered_events=events[columns]
withuproot.recreate("skimmedevents.root") asfout:
fout["Events"] =uproot_writeable(filtered_events)
reloaded=NanoEventsFactory.from_root({"skimmedevents.root": "Events"}, delayed=False).events()
print(reloaded.fields)
# This workssaveAndLoad(events, events.fields)
# This workssaveAndLoad(events, ["event", "run", "luminosityBlock"])
# This workssaveAndLoad(events, ["event", "run", "luminosityBlock", "Electron", "Muon", "HLT"])
# This does not worksaveAndLoad(events, ["event", "run", "luminosityBlock", "Electron", "Jet"])
Expected behavior
It is expected that column-trimmed files should be able to be loaded by NanoEventsFactory and have the same content and cross-references where possible.
Version Info
coffea: 2024.6.1
awkward: 2.6.5
uproot: 5.3.10
The text was updated successfully, but these errors were encountered:
Describe the bug
Reading root files which have been saved using the prescription #735 (comment) with column-filtering cannot be loaded by
NanoEventsFactory
usingNanoAODSchema
. Depending on the saved fields, the following exception is thrown:The stack trace is quite deep and can be generated with the below example.
To Reproduce
Below is a small example script that demonstrates the behavior, where an exception is raised when trying to load the
Expected behavior
It is expected that column-trimmed files should be able to be loaded by
NanoEventsFactory
and have the same content and cross-references where possible.Version Info
The text was updated successfully, but these errors were encountered: