File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 48
48
from pandas .core .dtypes .generic import (
49
49
ABCDataFrame ,
50
50
ABCIndex ,
51
+ ABCMultiIndex ,
51
52
ABCSeries ,
52
53
)
53
54
from pandas .core .dtypes .missing import (
@@ -1198,13 +1199,18 @@ def factorize(
1198
1199
if uniques .dtype == np .float16 :
1199
1200
uniques = uniques .astype (np .float32 )
1200
1201
1201
- if isinstance (self , ABCIndex ):
1202
- # preserve e.g. MultiIndex
1202
+ if isinstance (self , ABCMultiIndex ):
1203
+ # preserve MultiIndex
1203
1204
uniques = self ._constructor (uniques )
1204
1205
else :
1205
1206
from pandas import Index
1206
1207
1207
- uniques = Index (uniques )
1208
+ try :
1209
+ uniques = Index (uniques , dtype = self .dtype )
1210
+ except NotImplementedError :
1211
+ # not all dtypes are supported in Index that are allowed for Series
1212
+ # e.g. float16 or bytes
1213
+ uniques = Index (uniques )
1208
1214
return codes , uniques
1209
1215
1210
1216
_shared_docs [
You can’t perform that action at this time.
0 commit comments