Skip to content

Commit e1f393c

Browse files
committed
[python][RDF] Handle the creation of an empty RDataFrame in _MakeNumpyDataFrame
1 parent cdc439c commit e1f393c

File tree

1 file changed

+7
-1
lines changed
  • bindings/pyroot/pythonizations/python/ROOT/_pythonization

1 file changed

+7
-1
lines changed

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_rdataframe.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,21 @@ def pythonize_rdataframe(klass):
481481

482482

483483
def _make_name_rvec_pair(key, value):
484+
import numpy as np
485+
484486
import ROOT
485487

486488
# Get name of key
487489
if not isinstance(key, str):
488490
raise RuntimeError("Object not convertible: Dictionary key is not convertible to a string.")
489491

492+
if not np.any(value):
493+
# If the array is empty, we convert the type from object to short to create a default empty RVec
494+
value = value.astype(np.int16)
495+
490496
# Convert value to RVec and attach to dictionary
491497
pyvec = ROOT.VecOps.AsRVec(value)
492-
if not pyvec:
498+
if not pyvec and np.any(value):
493499
raise RuntimeError("Object not convertible: Dictionary entry " + key + " is not convertible with AsRVec.")
494500

495501
# Add pairs of column name and associated RVec to signature

0 commit comments

Comments
 (0)