14
14
pass
15
15
16
16
17
- class Concat :
18
- def setup (self ):
19
- N = 10 ** 5
20
- self .s = pd .Series (list ("aabbcd" ) * N ).astype ("category" )
21
-
22
- self .a = pd .Categorical (list ("aabbcd" ) * N )
23
- self .b = pd .Categorical (list ("bbcdjk" ) * N )
24
-
25
- def time_concat (self ):
26
- pd .concat ([self .s , self .s ])
27
-
28
- def time_union (self ):
29
- union_categoricals ([self .a , self .b ])
30
-
31
-
32
17
class Constructor :
33
18
def setup (self ):
34
19
N = 10 ** 5
@@ -77,14 +62,41 @@ def time_existing_series(self):
77
62
pd .Categorical (self .series )
78
63
79
64
65
+ class CategoricalOps :
66
+ params = ["__lt__" , "__le__" , "__eq__" , "__ne__" , "__ge__" , "__gt__" ]
67
+ param_names = ["op" ]
68
+
69
+ def setup (self , op ):
70
+ N = 10 ** 5
71
+ self .cat = pd .Categorical (list ("aabbcd" ) * N , ordered = True )
72
+
73
+ def time_categorical_op (self , op ):
74
+ getattr (self .cat , op )("b" )
75
+
76
+
77
+ class Concat :
78
+ def setup (self ):
79
+ N = 10 ** 5
80
+ self .s = pd .Series (list ("aabbcd" ) * N ).astype ("category" )
81
+
82
+ self .a = pd .Categorical (list ("aabbcd" ) * N )
83
+ self .b = pd .Categorical (list ("bbcdjk" ) * N )
84
+
85
+ def time_concat (self ):
86
+ pd .concat ([self .s , self .s ])
87
+
88
+ def time_union (self ):
89
+ union_categoricals ([self .a , self .b ])
90
+
91
+
80
92
class ValueCounts :
81
93
82
94
params = [True , False ]
83
95
param_names = ["dropna" ]
84
96
85
97
def setup (self , dropna ):
86
98
n = 5 * 10 ** 5
87
- arr = ["s{:04d}" . format ( i ) for i in np .random .randint (0 , n // 10 , size = n )]
99
+ arr = [f "s{ i :04d} " for i in np .random .randint (0 , n // 10 , size = n )]
88
100
self .ts = pd .Series (arr ).astype ("category" )
89
101
90
102
def time_value_counts (self , dropna ):
@@ -102,7 +114,7 @@ def time_rendering(self):
102
114
class SetCategories :
103
115
def setup (self ):
104
116
n = 5 * 10 ** 5
105
- arr = ["s{:04d}" . format ( i ) for i in np .random .randint (0 , n // 10 , size = n )]
117
+ arr = [f "s{ i :04d} " for i in np .random .randint (0 , n // 10 , size = n )]
106
118
self .ts = pd .Series (arr ).astype ("category" )
107
119
108
120
def time_set_categories (self ):
@@ -112,7 +124,7 @@ def time_set_categories(self):
112
124
class RemoveCategories :
113
125
def setup (self ):
114
126
n = 5 * 10 ** 5
115
- arr = ["s{:04d}" . format ( i ) for i in np .random .randint (0 , n // 10 , size = n )]
127
+ arr = [f "s{ i :04d} " for i in np .random .randint (0 , n // 10 , size = n )]
116
128
self .ts = pd .Series (arr ).astype ("category" )
117
129
118
130
def time_remove_categories (self ):
@@ -164,9 +176,9 @@ def setup(self, dtype):
164
176
np .random .seed (1234 )
165
177
n = 5 * 10 ** 5
166
178
sample_size = 100
167
- arr = [ i for i in np .random .randint (0 , n // 10 , size = n )]
179
+ arr = list ( np .random .randint (0 , n // 10 , size = n ))
168
180
if dtype == "object" :
169
- arr = ["s{:04d}" . format ( i ) for i in arr ]
181
+ arr = [f "s{ i :04d} " for i in arr ]
170
182
self .sample = np .random .choice (arr , sample_size )
171
183
self .series = pd .Series (arr ).astype ("category" )
172
184
@@ -225,7 +237,7 @@ def setup(self, index):
225
237
elif index == "non_monotonic" :
226
238
self .data = pd .Categorical .from_codes ([0 , 1 , 2 ] * N , categories = categories )
227
239
else :
228
- raise ValueError ("Invalid index param: {}" . format ( index ) )
240
+ raise ValueError (f "Invalid index param: { index } " )
229
241
230
242
self .scalar = 10000
231
243
self .list = list (range (10000 ))
@@ -282,4 +294,18 @@ def time_sort_values(self):
282
294
self .index .sort_values (ascending = False )
283
295
284
296
297
+ class SearchSorted :
298
+ def setup (self ):
299
+ N = 10 ** 5
300
+ self .ci = tm .makeCategoricalIndex (N ).sort_values ()
301
+ self .c = self .ci .values
302
+ self .key = self .ci .categories [1 ]
303
+
304
+ def time_categorical_index_contains (self ):
305
+ self .ci .searchsorted (self .key )
306
+
307
+ def time_categorical_contains (self ):
308
+ self .c .searchsorted (self .key )
309
+
310
+
285
311
from .pandas_vb_common import setup # noqa: F401 isort:skip
0 commit comments