File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 19
19
is_scalar ,
20
20
)
21
21
from pandas .core .dtypes .dtypes import CategoricalDtype
22
+ from pandas .core .dtypes .generic import ABCCategorical , ABCSeries
22
23
from pandas .core .dtypes .missing import isna
23
24
24
25
from pandas .core import accessor
@@ -198,8 +199,14 @@ def __new__(
198
199
data = []
199
200
200
201
assert isinstance (dtype , CategoricalDtype ), dtype
201
- if not isinstance (data , Categorical ) or data .dtype != dtype :
202
+ if isinstance (data , (cls , ABCSeries )) and is_categorical_dtype (data ):
203
+ data = data .values
204
+
205
+ if not isinstance (data , ABCCategorical ):
202
206
data = Categorical (data , dtype = dtype )
207
+ elif isinstance (dtype , CategoricalDtype ) and dtype != data .dtype :
208
+ # we want to silently ignore dtype='category'
209
+ data = data ._set_dtype (dtype )
203
210
204
211
data = data .copy () if copy else data
205
212
You can’t perform that action at this time.
0 commit comments