1
+ import gc
2
+ import sys
1
3
import unittest
2
- import ROOT
4
+
3
5
import numpy as np
4
- import sys
5
- import gc
6
+ import ROOT
6
7
7
8
8
9
def get_maximum_for_dtype (dtype ):
@@ -11,6 +12,7 @@ def get_maximum_for_dtype(dtype):
11
12
if np .issubdtype (dtype , np .floating ):
12
13
return np .finfo (dtype ).max
13
14
15
+
14
16
def get_minimum_for_dtype (dtype ):
15
17
if np .issubdtype (dtype , np .integer ):
16
18
return np .iinfo (dtype ).min
@@ -25,9 +27,7 @@ class AsRVec(unittest.TestCase):
25
27
"""
26
28
27
29
# Helpers
28
- dtypes = [
29
- "int16" , "int32" , "int64" , "uint16" , "uint32" , "uint64" , "float32" , "float64" , "bool"
30
- ]
30
+ dtypes = ["int16" , "int32" , "int64" , "uint16" , "uint32" , "uint64" , "float32" , "float64" , "bool" ]
31
31
32
32
def check_memory_adoption (self , root_obj , np_obj ):
33
33
np_obj [0 ] = get_maximum_for_dtype (np_obj .dtype )
@@ -49,12 +49,11 @@ 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
52
def test_object_dtype_strings (self ):
54
53
"""
55
54
Test adoption of numpy arrays with dtype=object and dtype=str containing strings
56
55
"""
57
- for dtype in [object , np .str_ , ' <U13' ]:
56
+ for dtype in [object , np .str_ , " <U13" ]:
58
57
with self .subTest (dtype = dtype ):
59
58
np_obj = np .array (["test_string_1" , "test_string_2" ], dtype = dtype )
60
59
root_obj = ROOT .VecOps .AsRVec (np_obj )
@@ -63,10 +62,9 @@ def test_object_dtype_strings(self):
63
62
self .assertEqual (root_obj [0 ], np_obj [0 ])
64
63
self .assertEqual (root_obj [1 ], np_obj [1 ])
65
64
66
-
67
65
def test_object_dtype_mixed_types (self ):
68
66
"""
69
- Test that a TypeError is raised for numpy arrays with dtype=object
67
+ Test that a TypeError is raised for numpy arrays with dtype=object
70
68
containing elements of different types
71
69
"""
72
70
np_obj = np .array (["string" , {}], dtype = object )
@@ -76,7 +74,6 @@ def test_object_dtype_mixed_types(self):
76
74
77
75
self .assertIn ("All elements in the numpy array must be of the same type" , str (context .exception ))
78
76
79
-
80
77
def test_multidim (self ):
81
78
"""
82
79
Test adoption of multi-dimensional numpy arrays
@@ -142,5 +139,5 @@ def test_refcount(self):
142
139
self .assertEqual (sys .getrefcount (np_obj ), 2 )
143
140
144
141
145
- if __name__ == ' __main__' :
142
+ if __name__ == " __main__" :
146
143
unittest .main ()
0 commit comments