2222 is_sparse ,
2323)
2424from pandas .core .dtypes .concat import concat_compat
25- from pandas .core .dtypes .generic import ABCDataFrame , ABCSeries
25+ from pandas .core .dtypes .generic import ABCDataFrame , ABCMultiIndex , ABCSeries
2626from pandas .core .dtypes .missing import _infer_fill_value , isna
2727
2828import pandas .core .common as com
29- from pandas .core .index import Index , InvalidIndexError , MultiIndex
29+ from pandas .core .index import Index , InvalidIndexError
3030from pandas .core .indexers import is_list_like_indexer , length_of_indexer
3131
3232
@@ -172,7 +172,7 @@ def _get_setitem_indexer(self, key):
172172
173173 ax = self .obj ._get_axis (0 )
174174
175- if isinstance (ax , MultiIndex ) and self .name != "iloc" :
175+ if isinstance (ax , ABCMultiIndex ) and self .name != "iloc" :
176176 try :
177177 return ax .get_loc (key )
178178 except Exception :
@@ -241,7 +241,7 @@ def _has_valid_tuple(self, key: Tuple):
241241 )
242242
243243 def _is_nested_tuple_indexer (self , tup : Tuple ):
244- if any (isinstance (ax , MultiIndex ) for ax in self .obj .axes ):
244+ if any (isinstance (ax , ABCMultiIndex ) for ax in self .obj .axes ):
245245 return any (is_nested_tuple (tup , ax ) for ax in self .obj .axes )
246246 return False
247247
@@ -329,7 +329,7 @@ def _setitem_with_indexer(self, indexer, value):
329329 # GH 10360, GH 27841
330330 if isinstance (indexer , tuple ) and len (indexer ) == len (self .obj .axes ):
331331 for i , ax in zip (indexer , self .obj .axes ):
332- if isinstance (ax , MultiIndex ) and not (
332+ if isinstance (ax , ABCMultiIndex ) and not (
333333 is_integer (i ) or com .is_null_slice (i )
334334 ):
335335 take_split_path = True
@@ -422,7 +422,9 @@ def _setitem_with_indexer(self, indexer, value):
422422
423423 # if we have a partial multiindex, then need to adjust the plane
424424 # indexer here
425- if len (labels ) == 1 and isinstance (self .obj [labels [0 ]].axes [0 ], MultiIndex ):
425+ if len (labels ) == 1 and isinstance (
426+ self .obj [labels [0 ]].axes [0 ], ABCMultiIndex
427+ ):
426428 item = labels [0 ]
427429 obj = self .obj [item ]
428430 index = obj .index
@@ -495,7 +497,7 @@ def setter(item, v):
495497 # we have an equal len Frame
496498 if isinstance (value , ABCDataFrame ):
497499 sub_indexer = list (indexer )
498- multiindex_indexer = isinstance (labels , MultiIndex )
500+ multiindex_indexer = isinstance (labels , ABCMultiIndex )
499501
500502 for item in labels :
501503 if item in value :
@@ -777,8 +779,8 @@ def _align_frame(self, indexer, df: ABCDataFrame):
777779 # we have a multi-index and are trying to align
778780 # with a particular, level GH3738
779781 if (
780- isinstance (ax , MultiIndex )
781- and isinstance (df .index , MultiIndex )
782+ isinstance (ax , ABCMultiIndex )
783+ and isinstance (df .index , ABCMultiIndex )
782784 and ax .nlevels != df .index .nlevels
783785 ):
784786 raise TypeError (
@@ -904,7 +906,7 @@ def _getitem_lowerdim(self, tup: Tuple):
904906 ax0 = self .obj ._get_axis (0 )
905907 # ...but iloc should handle the tuple as simple integer-location
906908 # instead of checking it as multiindex representation (GH 13797)
907- if isinstance (ax0 , MultiIndex ) and self .name != "iloc" :
909+ if isinstance (ax0 , ABCMultiIndex ) and self .name != "iloc" :
908910 result = self ._handle_lowerdim_multi_index_axis0 (tup )
909911 if result is not None :
910912 return result
@@ -1004,7 +1006,7 @@ def _getitem_axis(self, key, axis: int):
10041006 if isinstance (key , slice ):
10051007 return self ._get_slice_axis (key , axis = axis )
10061008 elif is_list_like_indexer (key ) and not (
1007- isinstance (key , tuple ) and isinstance (labels , MultiIndex )
1009+ isinstance (key , tuple ) and isinstance (labels , ABCMultiIndex )
10081010 ):
10091011
10101012 if hasattr (key , "ndim" ) and key .ndim > 1 :
@@ -1017,7 +1019,7 @@ def _getitem_axis(self, key, axis: int):
10171019 key = labels ._maybe_cast_indexer (key )
10181020
10191021 if is_integer (key ):
1020- if axis == 0 and isinstance (labels , MultiIndex ):
1022+ if axis == 0 and isinstance (labels , ABCMultiIndex ):
10211023 try :
10221024 return self ._get_label (key , axis = axis )
10231025 except (KeyError , TypeError ):
@@ -1228,7 +1230,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
12281230 try :
12291231 return labels .get_loc (obj )
12301232 except LookupError :
1231- if isinstance (obj , tuple ) and isinstance (labels , MultiIndex ):
1233+ if isinstance (obj , tuple ) and isinstance (labels , ABCMultiIndex ):
12321234 if len (obj ) == labels .nlevels :
12331235 return {"key" : obj }
12341236 raise
@@ -1248,7 +1250,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
12481250 # always valid
12491251 return {"key" : obj }
12501252
1251- if obj >= self .obj .shape [axis ] and not isinstance (labels , MultiIndex ):
1253+ if obj >= self .obj .shape [axis ] and not isinstance (labels , ABCMultiIndex ):
12521254 # a positional
12531255 raise ValueError ("cannot set by positional indexing with enlargement" )
12541256
@@ -1715,7 +1717,7 @@ def _is_scalar_access(self, key: Tuple):
17151717 return False
17161718
17171719 ax = self .obj .axes [i ]
1718- if isinstance (ax , MultiIndex ):
1720+ if isinstance (ax , ABCMultiIndex ):
17191721 return False
17201722
17211723 if isinstance (k , str ) and ax ._supports_partial_string_indexing :
@@ -1737,7 +1739,7 @@ def _getitem_scalar(self, key):
17371739 def _get_partial_string_timestamp_match_key (self , key , labels ):
17381740 """Translate any partial string timestamp matches in key, returning the
17391741 new key (GH 10331)"""
1740- if isinstance (labels , MultiIndex ):
1742+ if isinstance (labels , ABCMultiIndex ):
17411743 if (
17421744 isinstance (key , str )
17431745 and labels .levels [0 ]._supports_partial_string_indexing
@@ -1781,7 +1783,7 @@ def _getitem_axis(self, key, axis: int):
17811783 # to a list of keys
17821784 # we will use the *values* of the object
17831785 # and NOT the index if its a PandasObject
1784- if isinstance (labels , MultiIndex ):
1786+ if isinstance (labels , ABCMultiIndex ):
17851787
17861788 if isinstance (key , (ABCSeries , np .ndarray )) and key .ndim <= 1 :
17871789 # Series, or 0,1 ndim ndarray
@@ -1809,7 +1811,7 @@ def _getitem_axis(self, key, axis: int):
18091811 key = tuple ([key ])
18101812
18111813 # an iterable multi-selection
1812- if not (isinstance (key , tuple ) and isinstance (labels , MultiIndex )):
1814+ if not (isinstance (key , tuple ) and isinstance (labels , ABCMultiIndex )):
18131815
18141816 if hasattr (key , "ndim" ) and key .ndim > 1 :
18151817 raise ValueError ("Cannot index with multidimensional key" )
@@ -2474,7 +2476,7 @@ def is_nested_tuple(tup, labels):
24742476 for i , k in enumerate (tup ):
24752477
24762478 if is_list_like (k ) or isinstance (k , slice ):
2477- return isinstance (labels , MultiIndex )
2479+ return isinstance (labels , ABCMultiIndex )
24782480
24792481 return False
24802482
0 commit comments