@@ -49,6 +49,34 @@ def test_dtypes(self):
49
49
self .check_memory_adoption (root_obj , np_obj )
50
50
self .check_size (2 , root_obj )
51
51
52
+
53
+ def test_object_dtype_strings (self ):
54
+ """
55
+ Test adoption of numpy arrays with dtype=object and dtype=str containing strings
56
+ """
57
+ for dtype in [object , np .str_ , '<U13' ]:
58
+ with self .subTest (dtype = dtype ):
59
+ np_obj = np .array (["test_string_1" , "test_string_2" ], dtype = dtype )
60
+ root_obj = ROOT .VecOps .AsRVec (np_obj )
61
+
62
+ self .check_size (2 , root_obj )
63
+ self .assertEqual (root_obj [0 ], np_obj [0 ])
64
+ self .assertEqual (root_obj [1 ], np_obj [1 ])
65
+
66
+
67
+ def test_object_dtype_mixed_types (self ):
68
+ """
69
+ Test that a TypeError is raised for numpy arrays with dtype=object
70
+ containing elements of different types
71
+ """
72
+ np_obj = np .array (["string" , {}], dtype = object )
73
+
74
+ with self .assertRaises (TypeError ) as context :
75
+ ROOT .VecOps .AsRVec (np_obj )
76
+
77
+ self .assertIn ("All elements in the numpy array of objects must be of the same type" , str (context .exception ))
78
+
79
+
52
80
def test_multidim (self ):
53
81
"""
54
82
Test adoption of multi-dimensional numpy arrays
0 commit comments