14
14
Tuple ,
15
15
TypeVar ,
16
16
Union ,
17
+ cast ,
17
18
)
18
19
import warnings
19
20
102
103
)
103
104
104
105
if TYPE_CHECKING :
105
- from pandas import RangeIndex , Series
106
+ from pandas import MultiIndex , RangeIndex , Series
106
107
107
108
108
109
__all__ = ["Index" ]
@@ -1575,6 +1576,7 @@ def droplevel(self, level=0):
1575
1576
"levels: at least one level must be left."
1576
1577
)
1577
1578
# The two checks above guarantee that here self is a MultiIndex
1579
+ self = cast ("MultiIndex" , self )
1578
1580
1579
1581
new_levels = list (self .levels )
1580
1582
new_codes = list (self .codes )
@@ -3735,6 +3737,8 @@ def _get_leaf_sorter(labels):
3735
3737
left , right = right , left
3736
3738
how = {"right" : "left" , "left" : "right" }.get (how , how )
3737
3739
3740
+ assert isinstance (left , MultiIndex )
3741
+
3738
3742
level = left ._get_level_number (level )
3739
3743
old_level = left .levels [level ]
3740
3744
@@ -4780,7 +4784,7 @@ def get_indexer_for(self, target, **kwargs):
4780
4784
"""
4781
4785
if self ._index_as_unique :
4782
4786
return self .get_indexer (target , ** kwargs )
4783
- indexer , _ = self .get_indexer_non_unique (target , ** kwargs )
4787
+ indexer , _ = self .get_indexer_non_unique (target )
4784
4788
return indexer
4785
4789
4786
4790
@property
@@ -5409,24 +5413,24 @@ def _add_numeric_methods_binary(cls):
5409
5413
"""
5410
5414
Add in numeric methods.
5411
5415
"""
5412
- cls . __add__ = _make_arithmetic_op (operator .add , cls )
5413
- cls . __radd__ = _make_arithmetic_op (ops .radd , cls )
5414
- cls . __sub__ = _make_arithmetic_op (operator .sub , cls )
5415
- cls . __rsub__ = _make_arithmetic_op (ops .rsub , cls )
5416
- cls . __rpow__ = _make_arithmetic_op (ops .rpow , cls )
5417
- cls . __pow__ = _make_arithmetic_op (operator .pow , cls )
5418
-
5419
- cls . __truediv__ = _make_arithmetic_op (operator .truediv , cls )
5420
- cls . __rtruediv__ = _make_arithmetic_op (ops .rtruediv , cls )
5421
-
5422
- cls . __mod__ = _make_arithmetic_op (operator .mod , cls )
5423
- cls . __rmod__ = _make_arithmetic_op (ops .rmod , cls )
5424
- cls . __floordiv__ = _make_arithmetic_op (operator .floordiv , cls )
5425
- cls . __rfloordiv__ = _make_arithmetic_op (ops .rfloordiv , cls )
5426
- cls . __divmod__ = _make_arithmetic_op (divmod , cls )
5427
- cls . __rdivmod__ = _make_arithmetic_op (ops .rdivmod , cls )
5428
- cls . __mul__ = _make_arithmetic_op (operator .mul , cls )
5429
- cls . __rmul__ = _make_arithmetic_op (ops .rmul , cls )
5416
+ setattr ( cls , " __add__" , _make_arithmetic_op (operator .add , cls ) )
5417
+ setattr ( cls , " __radd__" , _make_arithmetic_op (ops .radd , cls ) )
5418
+ setattr ( cls , " __sub__" , _make_arithmetic_op (operator .sub , cls ) )
5419
+ setattr ( cls , " __rsub__" , _make_arithmetic_op (ops .rsub , cls ) )
5420
+ setattr ( cls , " __rpow__" , _make_arithmetic_op (ops .rpow , cls ) )
5421
+ setattr ( cls , " __pow__" , _make_arithmetic_op (operator .pow , cls ) )
5422
+
5423
+ setattr ( cls , " __truediv__" , _make_arithmetic_op (operator .truediv , cls ) )
5424
+ setattr ( cls , " __rtruediv__" , _make_arithmetic_op (ops .rtruediv , cls ) )
5425
+
5426
+ setattr ( cls , " __mod__" , _make_arithmetic_op (operator .mod , cls ) )
5427
+ setattr ( cls , " __rmod__" , _make_arithmetic_op (ops .rmod , cls ) )
5428
+ setattr ( cls , " __floordiv__" , _make_arithmetic_op (operator .floordiv , cls ) )
5429
+ setattr ( cls , " __rfloordiv__" , _make_arithmetic_op (ops .rfloordiv , cls ) )
5430
+ setattr ( cls , " __divmod__" , _make_arithmetic_op (divmod , cls ) )
5431
+ setattr ( cls , " __rdivmod__" , _make_arithmetic_op (ops .rdivmod , cls ) )
5432
+ setattr ( cls , " __mul__" , _make_arithmetic_op (operator .mul , cls ) )
5433
+ setattr ( cls , " __rmul__" , _make_arithmetic_op (ops .rmul , cls ) )
5430
5434
5431
5435
@classmethod
5432
5436
def _add_numeric_methods_unary (cls ):
@@ -5443,10 +5447,10 @@ def _evaluate_numeric_unary(self):
5443
5447
_evaluate_numeric_unary .__name__ = opstr
5444
5448
return _evaluate_numeric_unary
5445
5449
5446
- cls . __neg__ = _make_evaluate_unary (operator .neg , "__neg__" )
5447
- cls . __pos__ = _make_evaluate_unary (operator .pos , "__pos__" )
5448
- cls . __abs__ = _make_evaluate_unary (np .abs , "__abs__" )
5449
- cls . __inv__ = _make_evaluate_unary (lambda x : - x , "__inv__" )
5450
+ setattr ( cls , " __neg__" , _make_evaluate_unary (operator .neg , "__neg__" ) )
5451
+ setattr ( cls , " __pos__" , _make_evaluate_unary (operator .pos , "__pos__" ) )
5452
+ setattr ( cls , " __abs__" , _make_evaluate_unary (np .abs , "__abs__" ) )
5453
+ setattr ( cls , " __inv__" , _make_evaluate_unary (lambda x : - x , "__inv__" ) )
5450
5454
5451
5455
@classmethod
5452
5456
def _add_numeric_methods (cls ):
0 commit comments