Skip to content

Commit 6772d95

Browse files
qwhelanPingviinituutti
authored andcommitted
CLN: reduce overhead in setup for categoricals benchmarks in asv (pandas-dev#24913)
1 parent 5ce7ba4 commit 6772d95

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

asv_bench/benchmarks/categoricals.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,19 @@ class CategoricalSlicing(object):
223223

224224
def setup(self, index):
225225
N = 10**6
226-
values = list('a' * N + 'b' * N + 'c' * N)
227-
indices = {
228-
'monotonic_incr': pd.Categorical(values),
229-
'monotonic_decr': pd.Categorical(reversed(values)),
230-
'non_monotonic': pd.Categorical(list('abc' * N))}
231-
self.data = indices[index]
226+
categories = ['a', 'b', 'c']
227+
values = [0] * N + [1] * N + [2] * N
228+
if index == 'monotonic_incr':
229+
self.data = pd.Categorical.from_codes(values,
230+
categories=categories)
231+
elif index == 'monotonic_decr':
232+
self.data = pd.Categorical.from_codes(list(reversed(values)),
233+
categories=categories)
234+
elif index == 'non_monotonic':
235+
self.data = pd.Categorical.from_codes([0, 1, 2] * N,
236+
categories=categories)
237+
else:
238+
raise ValueError('Invalid index param: {}'.format(index))
232239

233240
self.scalar = 10000
234241
self.list = list(range(10000))

0 commit comments

Comments
 (0)