File tree 1 file changed +7
-1
lines changed
1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 25
25
from pandas .core .algorithms import take_1d
26
26
from pandas .core .arrays .categorical import Categorical , contains , recode_for_categories
27
27
import pandas .core .common as com
28
+ from pandas .core .construction import extract_array
28
29
import pandas .core .indexes .base as ibase
29
30
from pandas .core .indexes .base import Index , _index_shared_docs , maybe_extract_name
30
31
from pandas .core .indexes .extension import ExtensionIndex , inherit_names
@@ -198,8 +199,13 @@ 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
+ data = extract_array (data , extract_numpy = True )
203
+
204
+ if not isinstance (data , Categorical ):
202
205
data = Categorical (data , dtype = dtype )
206
+ elif isinstance (dtype , CategoricalDtype ) and dtype != data .dtype :
207
+ # we want to silently ignore dtype='category'
208
+ data = data ._set_dtype (dtype )
203
209
204
210
data = data .copy () if copy else data
205
211
You can’t perform that action at this time.
0 commit comments