|
58 | 58 | pandas_dtype,
|
59 | 59 | )
|
60 | 60 | from pandas.core.dtypes.dtypes import ExtensionDtype
|
61 |
| -from pandas.core.dtypes.generic import ( |
62 |
| - ABCDataFrame, |
63 |
| - ABCDatetimeIndex, |
64 |
| - ABCTimedeltaIndex, |
65 |
| -) |
| 61 | +from pandas.core.dtypes.generic import ABCDataFrame |
66 | 62 | from pandas.core.dtypes.missing import (
|
67 | 63 | array_equivalent,
|
68 | 64 | isna,
|
@@ -696,24 +692,25 @@ def from_frame(cls, df: DataFrame, sortorder=None, names=None) -> MultiIndex:
|
696 | 692 | @cache_readonly
|
697 | 693 | def _values(self) -> np.ndarray:
|
698 | 694 | # We override here, since our parent uses _data, which we don't use.
|
| 695 | + arr = lib.fast_zip(self._list_values) |
| 696 | + return arr |
| 697 | + |
| 698 | + @cache_readonly |
| 699 | + def _list_values(self) -> list: |
699 | 700 | values = []
|
700 | 701 |
|
701 | 702 | for i in range(self.nlevels):
|
702 | 703 | vals = self._get_level_values(i)
|
703 | 704 | if is_categorical_dtype(vals.dtype):
|
704 | 705 | vals = cast("CategoricalIndex", vals)
|
705 | 706 | vals = vals._data._internal_get_values()
|
706 |
| - if isinstance(vals.dtype, ExtensionDtype) or isinstance( |
707 |
| - vals, (ABCDatetimeIndex, ABCTimedeltaIndex) |
708 |
| - ): |
| 707 | + if isinstance(vals.dtype, ExtensionDtype) or hasattr(vals, "_box_values"): |
709 | 708 | vals = vals.astype(object)
|
710 | 709 | # error: Incompatible types in assignment (expression has type "ndarray",
|
711 | 710 | # variable has type "Index")
|
712 | 711 | vals = np.array(vals, copy=False) # type: ignore[assignment]
|
713 | 712 | values.append(vals)
|
714 |
| - |
715 |
| - arr = lib.fast_zip(values) |
716 |
| - return arr |
| 713 | + return values |
717 | 714 |
|
718 | 715 | @property
|
719 | 716 | def values(self) -> np.ndarray:
|
@@ -2709,7 +2706,7 @@ def _get_indexer(
|
2709 | 2706 | "for MultiIndex; see GitHub issue 9365"
|
2710 | 2707 | )
|
2711 | 2708 | else:
|
2712 |
| - indexer = self._engine.get_indexer(target._values) |
| 2709 | + indexer = self._engine.get_indexer(target._list_values) |
2713 | 2710 |
|
2714 | 2711 | # Note: we only get here (in extant tests at least) with
|
2715 | 2712 | # target.nlevels == self.nlevels
|
|
0 commit comments