Skip to content

Commit 9b85ca5

Browse files
siliataiderdpiparo
authored andcommitted
[python][RDF] Add tests for creating an RDataFrame from an empty array
1 parent b34e1f4 commit 9b85ca5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bindings/pyroot/pythonizations/test/rdataframe_makenumpy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ def test_object_dtype_strings(self):
3636
entries = df.AsNumpy()["x"]
3737
self.assertTrue(np.array_equal(entries, np.array(["test_string_1", "test_string_2"], dtype=object)))
3838

39+
def test_empty_arrays(self):
40+
"""
41+
Test creating an RDataFrame from an empty numpy array with different data types
42+
"""
43+
for dtype in self.dtypes:
44+
data = {"x": np.array([], dtype=dtype)}
45+
df = ROOT.RDF.FromNumpy(data)
46+
colnames = df.GetColumnNames()
47+
self.assertIn("x", colnames)
48+
self.assertEqual(df.Count().GetValue(), 0)
49+
50+
data_obj = {"x": np.array([], dtype="object")}
51+
with self.assertRaises(RuntimeError) as context:
52+
df = ROOT.RDF.FromNumpy(data_obj)
53+
54+
self.assertIn(
55+
"Failure in creating column 'x' for RDataFrame: the input column type is 'object', which is not supported. Make sure your column type is supported",
56+
str(context.exception),
57+
)
58+
3959
def test_multiple_columns(self):
4060
"""
4161
Test reading multiple columns

0 commit comments

Comments
 (0)