1
1
import numpy as np
2
2
3
- from pandas ._libs .index import (Int64Engine , UInt64Engine , Float64Engine ,
4
- ObjectEngine )
3
+ from pandas ._libs import index as libindex
4
+
5
+
6
+ def _get_numeric_engines ():
7
+ engine_names = [
8
+ ('Int64Engine' , np .int64 ), ('Int32Engine' , np .int32 ),
9
+ ('Int16Engine' , np .int16 ), ('Int8Engine' , np .int8 ),
10
+ ('UInt64Engine' , np .uint64 ), ('UInt32Engine' , np .uint32 ),
11
+ ('UInt16engine' , np .uint16 ), ('UInt8Engine' , np .uint8 ),
12
+ ('Float64Engine' , np .float64 ), ('Float32Engine' , np .float32 ),
13
+ ]
14
+ return [(getattr (libindex , engine_name ), dtype )
15
+ for engine_name , dtype in engine_names
16
+ if hasattr (libindex , engine_name )]
5
17
6
18
7
19
class NumericEngineIndexing (object ):
8
20
9
- params = [[Int64Engine , UInt64Engine , Float64Engine ],
10
- [np .int64 , np .uint64 , np .float64 ],
21
+ params = [_get_numeric_engines (),
11
22
['monotonic_incr' , 'monotonic_decr' , 'non_monotonic' ],
12
23
]
13
- param_names = ['engine' , 'dtype ' , 'index_type' ]
24
+ param_names = ['engine_and_dtype ' , 'index_type' ]
14
25
15
- def setup (self , engine , dtype , index_type ):
26
+ def setup (self , engine_and_dtype , index_type ):
27
+ engine , dtype = engine_and_dtype
16
28
N = 10 ** 5
17
29
values = list ([1 ] * N + [2 ] * N + [3 ] * N )
18
30
arr = {
@@ -26,7 +38,7 @@ def setup(self, engine, dtype, index_type):
26
38
# code belows avoids populating the mapping etc. while timing.
27
39
self .data .get_loc (2 )
28
40
29
- def time_get_loc (self , engine , dtype , index_type ):
41
+ def time_get_loc (self , engine_and_dtype , index_type ):
30
42
self .data .get_loc (2 )
31
43
32
44
@@ -44,7 +56,7 @@ def setup(self, index_type):
44
56
'non_monotonic' : np .array (list ('abc' ) * N , dtype = object ),
45
57
}[index_type ]
46
58
47
- self .data = ObjectEngine (lambda : arr , len (arr ))
59
+ self .data = libindex . ObjectEngine (lambda : arr , len (arr ))
48
60
# code belows avoids populating the mapping etc. while timing.
49
61
self .data .get_loc ('b' )
50
62
0 commit comments