scikit-hep / root_pandas

A Python module for conveniently loading/saving ROOT files as pandas DataFrames
MIT License
109 stars 35 forks source link

Ignored the following non-scalar branches #52

Closed nfoppiani closed 6 years ago

nfoppiani commented 6 years ago

I am trying to read a ttree with branches filled with vectors but it seems root_pandas is skipping them:

a = root_pandas.read_root("my_treeroot")
/home/nick/.local/lib/python3.6/site-packages/root_pandas/readwrite.py:221: UserWarning: Ignored the following non-scalar branches: <<branches names>>
  .format(bad_names=", ".join(nonscalar_columns)), UserWarning)

Isn't root_pandas suppose to read non scalar branches?

jonas-eschle commented 6 years ago

I think this is not supported in root_pandas (but I may be incorrect!). To my knowledge, root_pandas actively prevents this case to happen (at least it was like that before AFAIK). You can either use the flattening and have each entry in a single column or do what you really want by using root_numpy:

ar1 = root_numpy.root2array(filenames="rootfile.root",
                            treename='tree',
                            branches=['branch_with_array'])
df = pd.DataFrame(ar1)

(it used to work like that. If things changed in the mean time and this is not working anymore, let me know)

nfoppiani commented 6 years ago

Ok it seems you are right, though I found this commit https://github.com/scikit-hep/root_pandas/commit/28f2097ef22a36b4a5628dbe8166ffd7c55c1ef9#diff-f1a13e96d09db54e1548192242ca5ce4

in which it was decided to skip the non-scalar branches (it seems this functionality used to be supported before)

jonas-eschle commented 6 years ago

Yes, exactly. As said, it is (unfortunately!) actively suppressed in root_pandas as it is fully implemented in root_numpy (root_pandas uses internally root_numpy). Remove that piece of code and it will (presumably) work again.

That's why I still stick with root_numpy: it is too easy to convert to a DataFrame (see snippet above) and allows to convert arrays.

chrisburr commented 6 years ago

This is now supported in v0.3.1.