|
36 | 36 | from pandas.core.dtypes.concat import concat_compat |
37 | 37 | from pandas.core.dtypes.generic import ( |
38 | 38 | ABCDataFrame, |
39 | | - ABCMultiIndex, |
40 | 39 | ABCSeries, |
41 | 40 | ) |
42 | 41 | from pandas.core.dtypes.missing import ( |
|
53 | 52 | is_list_like_indexer, |
54 | 53 | length_of_indexer, |
55 | 54 | ) |
56 | | -from pandas.core.indexes.api import Index |
| 55 | +from pandas.core.indexes.api import ( |
| 56 | + Index, |
| 57 | + MultiIndex, |
| 58 | +) |
57 | 59 |
|
58 | 60 | if TYPE_CHECKING: |
59 | 61 | from pandas import ( |
@@ -642,7 +644,7 @@ def _get_setitem_indexer(self, key): |
642 | 644 |
|
643 | 645 | ax = self.obj._get_axis(0) |
644 | 646 |
|
645 | | - if isinstance(ax, ABCMultiIndex) and self.name != "iloc": |
| 647 | + if isinstance(ax, MultiIndex) and self.name != "iloc": |
646 | 648 | with suppress(TypeError, KeyError, InvalidIndexError): |
647 | 649 | # TypeError e.g. passed a bool |
648 | 650 | return ax.get_loc(key) |
@@ -690,7 +692,7 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None): |
690 | 692 |
|
691 | 693 | if ( |
692 | 694 | axis == column_axis |
693 | | - and not isinstance(self.obj.columns, ABCMultiIndex) |
| 695 | + and not isinstance(self.obj.columns, MultiIndex) |
694 | 696 | and is_list_like_indexer(key) |
695 | 697 | and not com.is_bool_indexer(key) |
696 | 698 | and all(is_hashable(k) for k in key) |
@@ -756,7 +758,7 @@ def _is_nested_tuple_indexer(self, tup: tuple) -> bool: |
756 | 758 | ------- |
757 | 759 | bool |
758 | 760 | """ |
759 | | - if any(isinstance(ax, ABCMultiIndex) for ax in self.obj.axes): |
| 761 | + if any(isinstance(ax, MultiIndex) for ax in self.obj.axes): |
760 | 762 | return any(is_nested_tuple(tup, ax) for ax in self.obj.axes) |
761 | 763 | return False |
762 | 764 |
|
@@ -817,7 +819,7 @@ def _getitem_lowerdim(self, tup: tuple): |
817 | 819 | ax0 = self.obj._get_axis(0) |
818 | 820 | # ...but iloc should handle the tuple as simple integer-location |
819 | 821 | # instead of checking it as multiindex representation (GH 13797) |
820 | | - if isinstance(ax0, ABCMultiIndex) and self.name != "iloc": |
| 822 | + if isinstance(ax0, MultiIndex) and self.name != "iloc": |
821 | 823 | with suppress(IndexingError): |
822 | 824 | return self._handle_lowerdim_multi_index_axis0(tup) |
823 | 825 |
|
@@ -996,7 +998,7 @@ def _is_scalar_access(self, key: tuple) -> bool: |
996 | 998 | return False |
997 | 999 |
|
998 | 1000 | ax = self.obj.axes[i] |
999 | | - if isinstance(ax, ABCMultiIndex): |
| 1001 | + if isinstance(ax, MultiIndex): |
1000 | 1002 | return False |
1001 | 1003 |
|
1002 | 1004 | if isinstance(k, str) and ax._supports_partial_string_indexing: |
@@ -1142,7 +1144,7 @@ def _getitem_axis(self, key, axis: int): |
1142 | 1144 | elif is_list_like_indexer(key): |
1143 | 1145 |
|
1144 | 1146 | # an iterable multi-selection |
1145 | | - if not (isinstance(key, tuple) and isinstance(labels, ABCMultiIndex)): |
| 1147 | + if not (isinstance(key, tuple) and isinstance(labels, MultiIndex)): |
1146 | 1148 |
|
1147 | 1149 | if hasattr(key, "ndim") and key.ndim > 1: |
1148 | 1150 | raise ValueError("Cannot index with multidimensional key") |
@@ -1205,20 +1207,20 @@ def _convert_to_indexer(self, key, axis: int, is_setter: bool = False): |
1205 | 1207 | is_int_index = labels.is_integer() |
1206 | 1208 | is_int_positional = is_integer(key) and not is_int_index |
1207 | 1209 |
|
1208 | | - if is_scalar(key) or isinstance(labels, ABCMultiIndex): |
| 1210 | + if is_scalar(key) or isinstance(labels, MultiIndex): |
1209 | 1211 | # Otherwise get_loc will raise InvalidIndexError |
1210 | 1212 |
|
1211 | 1213 | # if we are a label return me |
1212 | 1214 | try: |
1213 | 1215 | return labels.get_loc(key) |
1214 | 1216 | except LookupError: |
1215 | | - if isinstance(key, tuple) and isinstance(labels, ABCMultiIndex): |
| 1217 | + if isinstance(key, tuple) and isinstance(labels, MultiIndex): |
1216 | 1218 | if len(key) == labels.nlevels: |
1217 | 1219 | return {"key": key} |
1218 | 1220 | raise |
1219 | 1221 | except InvalidIndexError: |
1220 | 1222 | # GH35015, using datetime as column indices raises exception |
1221 | | - if not isinstance(labels, ABCMultiIndex): |
| 1223 | + if not isinstance(labels, MultiIndex): |
1222 | 1224 | raise |
1223 | 1225 | except TypeError: |
1224 | 1226 | pass |
@@ -1620,7 +1622,7 @@ def _setitem_with_indexer(self, indexer, value, name="iloc"): |
1620 | 1622 | # GH 10360, GH 27841 |
1621 | 1623 | if isinstance(indexer, tuple) and len(indexer) == len(self.obj.axes): |
1622 | 1624 | for i, ax in zip(indexer, self.obj.axes): |
1623 | | - if isinstance(ax, ABCMultiIndex) and not ( |
| 1625 | + if isinstance(ax, MultiIndex) and not ( |
1624 | 1626 | is_integer(i) or com.is_null_slice(i) |
1625 | 1627 | ): |
1626 | 1628 | take_split_path = True |
@@ -1819,7 +1821,7 @@ def _setitem_with_indexer_frame_value(self, indexer, value: DataFrame, name: str |
1819 | 1821 | sub_indexer = list(indexer) |
1820 | 1822 | pi = indexer[0] |
1821 | 1823 |
|
1822 | | - multiindex_indexer = isinstance(self.obj.columns, ABCMultiIndex) |
| 1824 | + multiindex_indexer = isinstance(self.obj.columns, MultiIndex) |
1823 | 1825 |
|
1824 | 1826 | unique_cols = value.columns.is_unique |
1825 | 1827 |
|
@@ -2163,8 +2165,8 @@ def _align_frame(self, indexer, df: DataFrame): |
2163 | 2165 | # we have a multi-index and are trying to align |
2164 | 2166 | # with a particular, level GH3738 |
2165 | 2167 | if ( |
2166 | | - isinstance(ax, ABCMultiIndex) |
2167 | | - and isinstance(df.index, ABCMultiIndex) |
| 2168 | + isinstance(ax, MultiIndex) |
| 2169 | + and isinstance(df.index, MultiIndex) |
2168 | 2170 | and ax.nlevels != df.index.nlevels |
2169 | 2171 | ): |
2170 | 2172 | raise TypeError( |
@@ -2428,7 +2430,7 @@ def is_nested_tuple(tup, labels) -> bool: |
2428 | 2430 |
|
2429 | 2431 | for k in tup: |
2430 | 2432 | if is_list_like(k) or isinstance(k, slice): |
2431 | | - return isinstance(labels, ABCMultiIndex) |
| 2433 | + return isinstance(labels, MultiIndex) |
2432 | 2434 |
|
2433 | 2435 | return False |
2434 | 2436 |
|
|
0 commit comments