Skip to content

Commit d2de56c

Browse files
committed
CLN: update asv benchmarks to reflect astype categorical deprecation
1 parent 47fd055 commit d2de56c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

asv_bench/benchmarks/categoricals.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pandas as pd
33
import pandas.util.testing as tm
4+
import warnings
45

56
try:
67
from pandas.api.types import union_categoricals
@@ -122,11 +123,16 @@ def setup(self):
122123
ncats = 100
123124

124125
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()
126+
self.s_str_cat = pd.Series(self.s_str, dtype="category")
127+
with warnings.catch_warnings(record=True):
128+
str_cat_type = pd.CategoricalDtype(set(self.s_str), ordered=True)
129+
self.s_str_cat_ordered = self.s_str.astype(str_cat_type)
130+
127131
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()
132+
self.s_int_cat = pd.Series(self.s_int, dtype="category")
133+
with warnings.catch_warnings(record=True):
134+
int_cat_type = pd.CategoricalDtype(set(self.s_int), ordered=True)
135+
self.s_int_cat_ordered = self.s_int.astype(int_cat_type)
130136

131137
def time_rank_string(self):
132138
self.s_str.rank()

0 commit comments

Comments
 (0)