Skip to content

Commit 9c8d273

Browse files
committed
CLN: use CategoricalIndex.from_codes in benchmark setup for performance
1 parent 5761e35 commit 9c8d273

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

asv_bench/benchmarks/categoricals.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,16 @@ class CategoricalSlicing(object):
223223

224224
def setup(self, index):
225225
N = 10**6
226-
values = list('a' * N + 'b' * N + 'c' * N)
226+
categories = ['a', 'b', 'c']
227+
values = [0] * N + [1] * N + [2] * N
227228
indices = {
228-
'monotonic_incr': pd.Categorical(values),
229-
'monotonic_decr': pd.Categorical(reversed(values)),
230-
'non_monotonic': pd.Categorical(list('abc' * N))}
229+
'monotonic_incr': pd.Categorical.from_codes(values,
230+
categories=categories),
231+
'monotonic_decr': pd.Categorical.from_codes(list(reversed(values)),
232+
categories=categories),
233+
'non_monotonic': pd.Categorical.from_codes([0, 1, 2] * N,
234+
categories=categories)
235+
}
231236
self.data = indices[index]
232237

233238
self.scalar = 10000

0 commit comments

Comments
 (0)