22
22
is_sparse ,
23
23
)
24
24
from 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
26
26
from pandas .core .dtypes .missing import _infer_fill_value , isna
27
27
28
28
import pandas .core .common as com
29
- from pandas .core .index import Index , InvalidIndexError , MultiIndex
29
+ from pandas .core .index import Index , InvalidIndexError
30
30
from pandas .core .indexers import is_list_like_indexer , length_of_indexer
31
31
32
32
@@ -172,7 +172,7 @@ def _get_setitem_indexer(self, key):
172
172
173
173
ax = self .obj ._get_axis (0 )
174
174
175
- if isinstance (ax , MultiIndex ) and self .name != "iloc" :
175
+ if isinstance (ax , ABCMultiIndex ) and self .name != "iloc" :
176
176
try :
177
177
return ax .get_loc (key )
178
178
except Exception :
@@ -241,7 +241,7 @@ def _has_valid_tuple(self, key: Tuple):
241
241
)
242
242
243
243
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 ):
245
245
return any (is_nested_tuple (tup , ax ) for ax in self .obj .axes )
246
246
return False
247
247
@@ -329,7 +329,7 @@ def _setitem_with_indexer(self, indexer, value):
329
329
# GH 10360, GH 27841
330
330
if isinstance (indexer , tuple ) and len (indexer ) == len (self .obj .axes ):
331
331
for i , ax in zip (indexer , self .obj .axes ):
332
- if isinstance (ax , MultiIndex ) and not (
332
+ if isinstance (ax , ABCMultiIndex ) and not (
333
333
is_integer (i ) or com .is_null_slice (i )
334
334
):
335
335
take_split_path = True
@@ -422,7 +422,9 @@ def _setitem_with_indexer(self, indexer, value):
422
422
423
423
# if we have a partial multiindex, then need to adjust the plane
424
424
# 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
+ ):
426
428
item = labels [0 ]
427
429
obj = self .obj [item ]
428
430
index = obj .index
@@ -495,7 +497,7 @@ def setter(item, v):
495
497
# we have an equal len Frame
496
498
if isinstance (value , ABCDataFrame ):
497
499
sub_indexer = list (indexer )
498
- multiindex_indexer = isinstance (labels , MultiIndex )
500
+ multiindex_indexer = isinstance (labels , ABCMultiIndex )
499
501
500
502
for item in labels :
501
503
if item in value :
@@ -777,8 +779,8 @@ def _align_frame(self, indexer, df: ABCDataFrame):
777
779
# we have a multi-index and are trying to align
778
780
# with a particular, level GH3738
779
781
if (
780
- isinstance (ax , MultiIndex )
781
- and isinstance (df .index , MultiIndex )
782
+ isinstance (ax , ABCMultiIndex )
783
+ and isinstance (df .index , ABCMultiIndex )
782
784
and ax .nlevels != df .index .nlevels
783
785
):
784
786
raise TypeError (
@@ -904,7 +906,7 @@ def _getitem_lowerdim(self, tup: Tuple):
904
906
ax0 = self .obj ._get_axis (0 )
905
907
# ...but iloc should handle the tuple as simple integer-location
906
908
# 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" :
908
910
result = self ._handle_lowerdim_multi_index_axis0 (tup )
909
911
if result is not None :
910
912
return result
@@ -1004,7 +1006,7 @@ def _getitem_axis(self, key, axis: int):
1004
1006
if isinstance (key , slice ):
1005
1007
return self ._get_slice_axis (key , axis = axis )
1006
1008
elif is_list_like_indexer (key ) and not (
1007
- isinstance (key , tuple ) and isinstance (labels , MultiIndex )
1009
+ isinstance (key , tuple ) and isinstance (labels , ABCMultiIndex )
1008
1010
):
1009
1011
1010
1012
if hasattr (key , "ndim" ) and key .ndim > 1 :
@@ -1017,7 +1019,7 @@ def _getitem_axis(self, key, axis: int):
1017
1019
key = labels ._maybe_cast_indexer (key )
1018
1020
1019
1021
if is_integer (key ):
1020
- if axis == 0 and isinstance (labels , MultiIndex ):
1022
+ if axis == 0 and isinstance (labels , ABCMultiIndex ):
1021
1023
try :
1022
1024
return self ._get_label (key , axis = axis )
1023
1025
except (KeyError , TypeError ):
@@ -1228,7 +1230,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
1228
1230
try :
1229
1231
return labels .get_loc (obj )
1230
1232
except LookupError :
1231
- if isinstance (obj , tuple ) and isinstance (labels , MultiIndex ):
1233
+ if isinstance (obj , tuple ) and isinstance (labels , ABCMultiIndex ):
1232
1234
if len (obj ) == labels .nlevels :
1233
1235
return {"key" : obj }
1234
1236
raise
@@ -1248,7 +1250,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
1248
1250
# always valid
1249
1251
return {"key" : obj }
1250
1252
1251
- if obj >= self .obj .shape [axis ] and not isinstance (labels , MultiIndex ):
1253
+ if obj >= self .obj .shape [axis ] and not isinstance (labels , ABCMultiIndex ):
1252
1254
# a positional
1253
1255
raise ValueError ("cannot set by positional indexing with enlargement" )
1254
1256
@@ -1715,7 +1717,7 @@ def _is_scalar_access(self, key: Tuple):
1715
1717
return False
1716
1718
1717
1719
ax = self .obj .axes [i ]
1718
- if isinstance (ax , MultiIndex ):
1720
+ if isinstance (ax , ABCMultiIndex ):
1719
1721
return False
1720
1722
1721
1723
if isinstance (k , str ) and ax ._supports_partial_string_indexing :
@@ -1737,7 +1739,7 @@ def _getitem_scalar(self, key):
1737
1739
def _get_partial_string_timestamp_match_key (self , key , labels ):
1738
1740
"""Translate any partial string timestamp matches in key, returning the
1739
1741
new key (GH 10331)"""
1740
- if isinstance (labels , MultiIndex ):
1742
+ if isinstance (labels , ABCMultiIndex ):
1741
1743
if (
1742
1744
isinstance (key , str )
1743
1745
and labels .levels [0 ]._supports_partial_string_indexing
@@ -1781,7 +1783,7 @@ def _getitem_axis(self, key, axis: int):
1781
1783
# to a list of keys
1782
1784
# we will use the *values* of the object
1783
1785
# and NOT the index if its a PandasObject
1784
- if isinstance (labels , MultiIndex ):
1786
+ if isinstance (labels , ABCMultiIndex ):
1785
1787
1786
1788
if isinstance (key , (ABCSeries , np .ndarray )) and key .ndim <= 1 :
1787
1789
# Series, or 0,1 ndim ndarray
@@ -1809,7 +1811,7 @@ def _getitem_axis(self, key, axis: int):
1809
1811
key = tuple ([key ])
1810
1812
1811
1813
# an iterable multi-selection
1812
- if not (isinstance (key , tuple ) and isinstance (labels , MultiIndex )):
1814
+ if not (isinstance (key , tuple ) and isinstance (labels , ABCMultiIndex )):
1813
1815
1814
1816
if hasattr (key , "ndim" ) and key .ndim > 1 :
1815
1817
raise ValueError ("Cannot index with multidimensional key" )
@@ -2474,7 +2476,7 @@ def is_nested_tuple(tup, labels):
2474
2476
for i , k in enumerate (tup ):
2475
2477
2476
2478
if is_list_like (k ) or isinstance (k , slice ):
2477
- return isinstance (labels , MultiIndex )
2479
+ return isinstance (labels , ABCMultiIndex )
2478
2480
2479
2481
return False
2480
2482
0 commit comments