Skip to content

Commit 26b2c1e

Browse files
committed
CLN: update asv benchmarks to reflect astype categorical deprecation
1 parent 7fcabe0 commit 26b2c1e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

asv_bench/benchmarks/categoricals.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ def setup(self):
122122
ncats = 100
123123

124124
self.s_str = pd.Series(tm.makeCategoricalIndex(N, ncats)).astype(str)
125-
self.s_str_cat = self.s_str.astype("category")
126-
self.s_str_cat_ordered = self.s_str_cat.cat.as_ordered()
125+
self.s_str_cat = pd.Series(self.s_str, dtype="category")
126+
with warnings.catch_warnings(record=True):
127+
str_cat_type = pd.CategoricalDtype(set(self.s_str), ordered=True)
128+
self.s_str_cat_ordered = self.s_str.astype(str_cat_type)
129+
127130
self.s_int = pd.Series(np.random.randint(0, ncats, size=N))
128-
self.s_int_cat = self.s_int.astype("category")
129-
self.s_int_cat_ordered = self.s_int_cat.cat.as_ordered()
131+
self.s_int_cat = pd.Series(self.s_int, dtype="category")
132+
with warnings.catch_warnings(record=True):
133+
int_cat_type = pd.Categorical(set(self.s_int), ordered=True)
134+
self.s_int_cat_ordered = self.s_int.astype(int_cat_type)
130135

131136
def time_rank_string(self):
132137
self.s_str.rank()

0 commit comments

Comments
 (0)