Skip to content

Commit 296c892

Browse files
committed
PERF: benchmark removing categories
1 parent c6e4693 commit 296c892

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

asv_bench/benchmarks/categoricals.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ 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, size=n)]
8888
self.ts = pd.Series(arr).astype('category')
8989

9090
def time_value_counts(self, dropna):
@@ -104,13 +104,24 @@ class SetCategories(object):
104104

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

110110
def time_set_categories(self):
111111
self.ts.cat.set_categories(self.ts.cat.categories[::2])
112112

113113

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

116127
def setup(self):
@@ -159,7 +170,7 @@ def setup(self, dtype):
159170
sample_size = 100
160171
arr = [i for i in np.random.randint(0, n // 10, size=n)]
161172
if dtype == 'object':
162-
arr = ['s%04d' % i for i in arr]
173+
arr = ['s{:04d}'.format(i) for i in arr]
163174
self.sample = np.random.choice(arr, sample_size)
164175
self.series = pd.Series(arr).astype('category')
165176

0 commit comments

Comments
 (0)