Skip to content

Commit 70b0855

Browse files
BUG: preserve (object) dtype in factorize
1 parent e3e198f commit 70b0855

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pandas/core/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from pandas.core.dtypes.generic import (
4545
ABCDataFrame,
4646
ABCIndex,
47+
ABCMultiIndex,
4748
ABCSeries,
4849
)
4950
from pandas.core.dtypes.missing import (
@@ -1287,13 +1288,13 @@ def factorize(
12871288
if uniques.dtype == np.float16:
12881289
uniques = uniques.astype(np.float32)
12891290

1290-
if isinstance(self, ABCIndex):
1291-
# preserve e.g. MultiIndex
1291+
if isinstance(self, ABCMultiIndex):
1292+
# preserve MultiIndex
12921293
uniques = self._constructor(uniques)
12931294
else:
12941295
from pandas import Index
12951296

1296-
uniques = Index(uniques)
1297+
uniques = Index(uniques, dtype=self.dtype)
12971298
return codes, uniques
12981299

12991300
_shared_docs["searchsorted"] = """

0 commit comments

Comments
 (0)