@@ -550,7 +550,7 @@ def __getitem__(self, key):
550
550
return super_getitem (key )
551
551
552
552
def __floordiv__ (self , other ):
553
- if is_integer (other ):
553
+ if is_integer (other ) and other != 0 :
554
554
if (len (self ) == 0 or
555
555
self ._start % other == 0 and
556
556
self ._step % other == 0 ):
@@ -592,26 +592,27 @@ def _evaluate_numeric_binop(self, other):
592
592
attrs = self ._get_attributes_dict ()
593
593
attrs = self ._maybe_update_attributes (attrs )
594
594
595
+ left , right = self , other
595
596
if reversed :
596
- self , other = other , self
597
+ left , right = right , left
597
598
598
599
try :
599
600
# apply if we have an override
600
601
if step :
601
602
with np .errstate (all = 'ignore' ):
602
- rstep = step (self ._step , other )
603
+ rstep = step (left ._step , right )
603
604
604
605
# we don't have a representable op
605
606
# so return a base index
606
607
if not is_integer (rstep ) or not rstep :
607
608
raise ValueError
608
609
609
610
else :
610
- rstep = self ._step
611
+ rstep = left ._step
611
612
612
613
with np .errstate (all = 'ignore' ):
613
- rstart = op (self ._start , other )
614
- rstop = op (self ._stop , other )
614
+ rstart = op (left ._start , right )
615
+ rstop = op (left ._stop , right )
615
616
616
617
result = RangeIndex (rstart ,
617
618
rstop ,
@@ -627,18 +628,12 @@ def _evaluate_numeric_binop(self, other):
627
628
628
629
return result
629
630
630
- except (ValueError , TypeError , AttributeError ):
631
- pass
632
-
633
- # convert to Int64Index ops
634
- if isinstance (self , RangeIndex ):
635
- self = self .values
636
- if isinstance (other , RangeIndex ):
637
- other = other .values
638
-
639
- with np .errstate (all = 'ignore' ):
640
- results = op (self , other )
641
- return Index (results , ** attrs )
631
+ except (ValueError , TypeError , AttributeError ,
632
+ ZeroDivisionError ):
633
+ # Defer to Int64Index implementation
634
+ if reversed :
635
+ return op (other , self ._int64index )
636
+ return op (self ._int64index , other )
642
637
643
638
return _evaluate_numeric_binop
644
639
0 commit comments