Pandas dataframe to TTree. Problem with types 'uint8' and 'int8'

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)

Hello,

Thank you for the report, indeed looking at the code it seems that int8 and uint8 are not supported data types in MakeNumpyDataFrame.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.