Skip to content

Commit bcc0f14

Browse files
committed
PERF: benchmark removing categories
1 parent 4c6240d commit bcc0f14

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

asv_bench/benchmarks/categoricals.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ class ValueCounts(object):
8484

8585
def setup(self, dropna):
8686
n = 5 * 10**5
87-
arr = ['s%04d' % i for i in np.random.randint(0, n // 10, size=n)]
87+
arr = ['s{:04d}'.format(i) for i in np.random.randint(0, n // 10,
88+
size=n)]
8889
self.ts = pd.Series(arr).astype('category')
8990

9091
def time_value_counts(self, dropna):
@@ -104,13 +105,26 @@ class SetCategories(object):
104105

105106
def setup(self):
106107
n = 5 * 10**5
107-
arr = ['s%04d' % i for i in np.random.randint(0, n // 10, size=n)]
108+
arr = ['s{:04d}'.format(i) for i in np.random.randint(0, n // 10,
109+
size=n)]
108110
self.ts = pd.Series(arr).astype('category')
109111

110112
def time_set_categories(self):
111113
self.ts.cat.set_categories(self.ts.cat.categories[::2])
112114

113115

116+
class RemoveCategories(object):
117+
118+
def setup(self):
119+
n = 5 * 10**5
120+
arr = ['s{:04d}'.format(i) for i in np.random.randint(0, n // 10,
121+
size=n)]
122+
self.ts = pd.Series(arr).astype('category')
123+
124+
def time_remove_categories(self):
125+
self.ts.cat.remove_categories(self.ts.cat.categories[::2])
126+
127+
114128
class Rank(object):
115129

116130
def setup(self):
@@ -159,7 +173,7 @@ def setup(self, dtype):
159173
sample_size = 100
160174
arr = [i for i in np.random.randint(0, n // 10, size=n)]
161175
if dtype == 'object':
162-
arr = ['s%04d' % i for i in arr]
176+
arr = ['s{:04d}'.format(i) for i in arr]
163177
self.sample = np.random.choice(arr, sample_size)
164178
self.series = pd.Series(arr).astype('category')
165179

0 commit comments

Comments
 (0)