@@ -807,24 +807,17 @@ def delete(self, loc) -> Index: # type: ignore[override]
807
807
return self [1 :]
808
808
if loc == - 1 or loc == len (self ) - 1 :
809
809
return self [:- 1 ]
810
+ if len (self ) == 3 and (loc == 1 or loc == - 2 ):
811
+ return self [::2 ]
810
812
811
813
elif lib .is_list_like (loc ):
812
814
slc = lib .maybe_indices_to_slice (np .asarray (loc , dtype = np .intp ), len (self ))
813
- if isinstance (slc , slice ) and slc .step is not None and slc .step < 0 :
814
- rng = range (len (self ))[slc ][::- 1 ]
815
- slc = slice (rng .start , rng .stop , rng .step )
816
-
817
- if isinstance (slc , slice ) and slc .step in [1 , None ]:
818
- # Note: maybe_indices_to_slice will never return a slice
819
- # with 'slc.start is None'; may have slc.stop None in cases
820
- # with negative step
821
- if slc .start == 0 :
822
- return self [slc .stop :]
823
- elif slc .stop in [len (self ), None ]:
824
- return self [: slc .start ]
825
-
826
- # TODO: more generally, self.difference(self[slc]),
827
- # once _difference is better about retaining RangeIndex
815
+
816
+ if isinstance (slc , slice ):
817
+ # defer to RangeIndex._difference, which is optimized to return
818
+ # a RangeIndex whenever possible
819
+ other = self [slc ]
820
+ return self .difference (other , sort = False )
828
821
829
822
return super ().delete (loc )
830
823
0 commit comments