When trying to convert a python array into a TTree, the method ROOT.RDF.MakeNumpyDataFrame(array)
does not work if the columns have dtypes ‘int8’ or ‘uint8’.
I managed to make my script work by changing them to int32
in the initial pandas’ data frame.
# df is a pandas dataframe
i8_columns = df.select_dtypes(['uint8']).columns
df[i8_columns] = df[i8_columns].apply(lambda x: x.astype('int32'))
# Convert data to a dictionary with arrays
arraydata = {key: df[key].values for key in df.keys()}
# Write in a TTree
import ROOT
rdf = ROOT.RDF.MakeNumpyDataFrame(arraydata)
rdf.Snapshot('mytree', 'myfile.root')
Just pointing it out since I could not find this issue anywhere.
(ROOT 6.24)