Hi!
I am trying to make a nparray dictionary from an RDataFrame as follows:
df_nosmear = ROOT.RDataFrame("dvcs", "./pseudo_KM15_BKM10_hallA_t2_nosmear_5pct.root")
np_nosmear = df_nosmear.AsNumpy()
and I get the following error:
/home/lily/opt/root_master/root_install/lib/ROOT/_pythonization/_rdataframe.py:290: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
tmp = numpy.empty(len(cpp_reference), dtype=numpy.object)
Traceback (most recent call last):
File "/media/lily/Data/GPDs/HallA/plots/drawpseudo.py", line 7, in <module>
np_nosmear = df_nosmear.AsNumpy()
File "/home/lily/opt/root_master/root_install/lib/ROOT/_pythonization/_rdataframe.py", line 239, in RDataFrameAsNumpy
return result.GetValue()
File "/home/lily/opt/root_master/root_install/lib/ROOT/_pythonization/_rdataframe.py", line 290, in GetValue
tmp = numpy.empty(len(cpp_reference), dtype=numpy.object)
File "/home/lily/.local/lib/python3.10/site-packages/numpy/__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'object_'?
>>>
I traced the problem to the fact that the .root file contains array branches. If I get only the branches that are not arrays for example np_nosmear = df_nosmear.AsNumpy(columns=["kinematics.k"])
it works.
This is how the root file tree was declared:
struct kin_t {
Double_t k;
Double_t QQ;
Double_t xB;
Double_t t;
};
kin_t kin;
Int_t set;
Int_t npoints;
Double_t phi[kMaxNumOfDataPts];
Double_t F_BH[kMaxNumOfDataPts], F_I[kMaxNumOfDataPts], F[kMaxNumOfDataPts], errF[kMaxNumOfDataPts];
Double_t varF;
Double_t gdvcs, dvcs, e_dvcs;
Double_t gReH, gReE, gReHtilde, gReEtilde, ReH, ReE, ReHtilde;
Double_t e_ReH, e_ReE, e_ReHtilde;
Double_t gImH, gImE, gImHtilde, gImEtilde;
TTree *t3 = new TTree("dvcs","generated dvcs");
t3->Branch("set",&set,"set/I");
t3->Branch("kinematics",&kin.k,"k/D:QQ:xB:t");
t3->Branch("npoints",&npoints,"npoints/I");
t3->Branch("phi",phi,"phi[npoints]/D");
t3->Branch("F",F,"F[npoints]/D");
t3->Branch("F_BH",F_BH,"F_BH[npoints]/D");
t3->Branch("F_I",F_I,"F_I[npoints]/D");
t3->Branch("gdvcs",&gdvcs,"gdvcs/D");
t3->Branch("errF",errF,"errF[npoints]/D");
t3->Branch("gReH",&gReH,"gReH/D");
t3->Branch("gReE",&gReE,"gReE/D");
t3->Branch("gReHtilde",&gReHtilde,"gReHtilde/D");
t3->Branch("gReEtilde",&gReEtilde,"gReEtilde/D");
t3->Branch("gImH",&gImH,"gImH/D");
t3->Branch("gImE",&gImE,"gImE/D");
t3->Branch("gImHtilde",&gImHtilde,"gImHtilde/D");
t3->Branch("gImEtilde",&gImEtilde,"gImEtilde/D");
I have attached the .root file and the ROOT version I am using is ROOT 6.27/01
I appreciate your help!
pseudo_KM15_BKM10_hallA_t2_nosmear_5pct.root (206.1 KB)
Please read tips for efficient and successful posting and posting code
Please fill also the fields below. Note that root -b -q
will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug
from the ROOT prompt to pre-populate a topic.
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided