1616from pandas .compat .numpy import function as nv
1717
1818import pandas .core .common as com
19+ from pandas .core import ops
1920from pandas .core .indexes .base import Index , _index_shared_docs
2021from pandas .util ._decorators import Appender , cache_readonly
2122import pandas .core .dtypes .concat as _concat
@@ -570,16 +571,12 @@ def __floordiv__(self, other):
570571 def _add_numeric_methods_binary (cls ):
571572 """ add in numeric methods, specialized to RangeIndex """
572573
573- def _make_evaluate_binop (op , opstr , reversed = False , step = False ):
574+ def _make_evaluate_binop (op , step = False ):
574575 """
575576 Parameters
576577 ----------
577578 op : callable that accepts 2 parms
578579 perform the binary op
579- opstr : string
580- string name of ops
581- reversed : boolean, default False
582- if this is a reversed op, e.g. radd
583580 step : callable, optional, default to False
584581 op to apply to the step parm if not None
585582 if False, use the existing step
@@ -594,17 +591,13 @@ def _evaluate_numeric_binop(self, other):
594591 elif isinstance (other , (timedelta , np .timedelta64 )):
595592 # GH#19333 is_integer evaluated True on timedelta64,
596593 # so we need to catch these explicitly
597- if reversed :
598- return op (other , self ._int64index )
599594 return op (self ._int64index , other )
600595
601- other = self ._validate_for_numeric_binop (other , op , opstr )
596+ other = self ._validate_for_numeric_binop (other , op )
602597 attrs = self ._get_attributes_dict ()
603598 attrs = self ._maybe_update_attributes (attrs )
604599
605600 left , right = self , other
606- if reversed :
607- left , right = right , left
608601
609602 try :
610603 # apply if we have an override
@@ -638,43 +631,26 @@ def _evaluate_numeric_binop(self, other):
638631
639632 return result
640633
641- except (ValueError , TypeError , AttributeError ,
642- ZeroDivisionError ):
634+ except (ValueError , TypeError , ZeroDivisionError ):
643635 # Defer to Int64Index implementation
644- if reversed :
645- return op (other , self ._int64index )
646636 return op (self ._int64index , other )
637+ # TODO: Do attrs get handled reliably?
647638
648639 return _evaluate_numeric_binop
649640
650- cls .__add__ = cls .__radd__ = _make_evaluate_binop (
651- operator .add , '__add__' )
652- cls .__sub__ = _make_evaluate_binop (operator .sub , '__sub__' )
653- cls .__rsub__ = _make_evaluate_binop (
654- operator .sub , '__sub__' , reversed = True )
655- cls .__mul__ = cls .__rmul__ = _make_evaluate_binop (
656- operator .mul ,
657- '__mul__' ,
658- step = operator .mul )
659- cls .__truediv__ = _make_evaluate_binop (
660- operator .truediv ,
661- '__truediv__' ,
662- step = operator .truediv )
663- cls .__rtruediv__ = _make_evaluate_binop (
664- operator .truediv ,
665- '__truediv__' ,
666- reversed = True ,
667- step = operator .truediv )
641+ cls .__add__ = _make_evaluate_binop (operator .add )
642+ cls .__radd__ = _make_evaluate_binop (ops .radd )
643+ cls .__sub__ = _make_evaluate_binop (operator .sub )
644+ cls .__rsub__ = _make_evaluate_binop (ops .rsub )
645+ cls .__mul__ = _make_evaluate_binop (operator .mul , step = operator .mul )
646+ cls .__rmul__ = _make_evaluate_binop (ops .rmul , step = ops .rmul )
647+ cls .__truediv__ = _make_evaluate_binop (operator .truediv ,
648+ step = operator .truediv )
649+ cls .__rtruediv__ = _make_evaluate_binop (ops .rtruediv ,
650+ step = ops .rtruediv )
668651 if not compat .PY3 :
669- cls .__div__ = _make_evaluate_binop (
670- operator .div ,
671- '__div__' ,
672- step = operator .div )
673- cls .__rdiv__ = _make_evaluate_binop (
674- operator .div ,
675- '__div__' ,
676- reversed = True ,
677- step = operator .div )
652+ cls .__div__ = _make_evaluate_binop (operator .div , step = operator .div )
653+ cls .__rdiv__ = _make_evaluate_binop (ops .rdiv , step = ops .rdiv )
678654
679655
680656RangeIndex ._add_numeric_methods ()
0 commit comments