Replies: 4 comments 2 replies
-
Could you include the whole stack trace and maybe a copy of the file? Is it able to read all of the branches with The "KeyError: ('nPV', nan)" is a bug; some step in the operation is trying to find a key in a dict that is a string and a number: >>> float("nan") == float("nan")
False So if a key in that dict included NaN, it shouldn't (in principle*) ever be accessible: >>> internal_dict = {("nPV", float("nan")): 3.14, ("nPV", 123): 2.71}
>>> internal_dict[("nPV", float("nan"))]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: ('nPV', nan)
>>> internal_dict[("nPV", 123)]
2.71 The Uproot code should not be allowing the second item of this tuple to be NaN. It's probably a computed value, and your data includes a NaN in it somewhere that is making the computed value also NaN. But I can't debug it if I don't see the details. *As a caveat, to say "in principle," NumPy's >>> internal_dict = {("nPV", np.nan): 3.14, ("nPV", 123): 2.71}
>>> internal_dict[("nPV", np.nan)]
3.14
>>> np.nan + 1
nan
>>> internal_dict[("nPV", np.nan + 1)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: ('nPV', nan) |
Beta Was this translation helpful? Give feedback.
-
Iibrary = 'np' is working but I am using library='pd' Here is the error KeyError Traceback (most recent call last) /Applications/anaconda3/lib/python3.8/site-packages/uproot/behaviors/TBranch.py in arrays(self, expressions, cut, filter_name, filter_typename, filter_branch, aliases, language, entry_start, entry_stop, decompression_executor, interpretation_executor, array_cache, library, how) /Applications/anaconda3/lib/python3.8/site-packages/uproot/interpretation/library.py in group(self, arrays, expression_context, how) /Applications/anaconda3/lib/python3.8/site-packages/uproot/interpretation/library.py in _pandas_memory_efficient(pandas, series, names) KeyError: ('nPV', nan) |
Beta Was this translation helpful? Give feedback.
-
It's being fixed in #449. The columns of your DataFrame must have multiple levels of structure (e.g. "Event" as an outer name and "run" as an inner name; "GenPhoton1" as an outer name and "pt" as an inner name) and also a single level of structure (just "nPV"). To make them the same length, I had been using However, it means that you'll have to access the "nPV" column as The error itself had nothing to do with reading, which was indicated by the fact that |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation. Now it makes lots of sense for me.
I can tell from the data frame, all other quantities have multi-indexing but nPV have single. Can I change double index quantities into single for example ('Event', 'run')->'Event_run'. I saw this type of indexing structure in root_pandas but it is now outdated. Is there any way we can apply same analogy here and read all root branches in pandas data frame? OR is there any better way to do this? |
Beta Was this translation helpful? Give feedback.
-
Hi, I am trying to using uproot to read root file into pandas data frame. The root file have some structured data branches some not.
tree.show()
name | typename | interpretation
---------------------+--------------------------+-------------------------------
Event | struct {int64_t run; ... | AsDtype("[('run', '>i8'), (...
GenPhoton1 | struct {double pt; do... | AsDtype("[('pt', '>f8'), ('...
GenPhoton2 | struct {double pt; do... | AsDtype("[('pt', '>f8'), ('...
Photon1 | struct {double pt; do... | AsDtype("[('pt', '>f8'), ('...
Photon2 | struct {double pt; do... | AsDtype("[('pt', '>f8'), ('...
Vertex0 | struct {double vx; do... | AsDtype("[('vx', '>f8'), ('...
PrimaryVertex | struct {double vx; do... | AsDtype("[('vx', '>f8'), ('...
nPV | int32_t | AsDtype('>i4')
BeamSpot | struct {double x0; do... | AsDtype("[('x0', '>f8'), ('...
I can see branch "nPV" is different from other branch that why I think I'm getting error when I'm trying to read this to pandas data frame.
KeyError: ('nPV', nan) -> This is the error showing.
If I remove "nPV" branch than it working fine.
Beta Was this translation helpful? Give feedback.
All reactions