Skip to content

Missing bool type in creating RDataFrame #18085

@aprozo

Description

@aprozo

Check duplicate issues.

  • Checked for duplicates

Description

cpp type of bool is not supported in converting pandas dataframe to RDF.

Reproducer

import ROOT
test_df = pandas.DataFrame( { 'test': [False, True]})
rdf=ROOT.RDF.FromPandas(test_df)

Output error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[26], line 1
----> 1 rdf=ROOT.RDF.FromPandas(test_df)

File .conda/lib/python3.11/site-packages/ROOT/_facade.py:357, in ROOTFacade.RDF.<locals>.MakePandasDataFrame(df)
    355 for key in df.columns:
    356     np_dict[key] = df[key].to_numpy()
--> 357 return _MakeNumpyDataFrame(np_dict)

File .conda/lib/python3.11/site-packages/ROOT/_pythonization/_rdataframe.py:514, in _MakeNumpyDataFrame(np_dict)
    512 _numpy_data[key] = (lambda: _numpy_data.pop(key), np_dict_copy)
    513 deleter = ROOT.std.function["void()"](_numpy_data[key][0])
--> 514 return ROOT.Internal.RDF.MakeRVecDataFrame(deleter, *args)

File /.conda/lib/python3.11/site-packages/ROOT/_pythonization/_rdataframe.py:491, in <genexpr>(.0)
    488 if len(np_dict) == 0:
    489     raise RuntimeError("Object not convertible: Dictionary is empty.")
--> 491 args = (_make_name_rvec_pair(key, value) for key, value in np_dict.items())
    493 # How we keep the NumPy arrays around as long as the RDataSource is alive:
    494 #
    495 #  1. Cache a container with references to the NumPy arrays in a global
   (...)    507 #
    508 # 4. The RDataSource calls the deleter in its destructor.
    510 np_dict_copy = dict(**np_dict)

File .conda/lib/python3.11/site-packages/ROOT/_pythonization/_rdataframe.py:460, in _make_name_rvec_pair(key, value)
    457     raise RuntimeError("Object not convertible: Dictionary key is not convertible to a string.")
    459 # Convert value to RVec and attach to dictionary
--> 460 pyvec = ROOT.VecOps.AsRVec(value)
    461 if not pyvec:
    462     raise RuntimeError("Object not convertible: Dictionary entry " + key + " is not convertible with AsRVec.")

File .conda/lib/python3.11/site-packages/ROOT/_pythonization/_rvec.py:130, in _AsRVec(arr)
    129 dtype = typestr[1:]
--> 130 cppdtype = _get_cpp_type_from_numpy_type(dtype)
    132 # Construct an RVec of the correct data-type
    133 out = ROOT.VecOps.RVec[cppdtype](ROOT.module.cppyy.ll.reinterpret_cast[f"{cppdtype} *"](data), size)

File .conda/lib/python3.11/site-packages/ROOT/_pythonization/_rvec.py:90, in _get_cpp_type_from_numpy_type(dtype)
     87 cpptypes = {"i4": "int", "u4": "unsigned int", "i8": "Long64_t", "u8": "ULong64_t", "f4": "float", "f8": "double"}
     89 if not dtype in cpptypes:
---> 90     raise RuntimeError("Object not convertible: Python object has unknown data-type '" + dtype + "'.")
     92 return cpptypes[dtype]

RuntimeError: Object not convertible: Python object has unknown data-type 'b1'.

ROOT version

6.34.04

Installation method

pre-built

Operating system

Linux Ubuntu 22.04 on WSL2

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions