@@ -3231,6 +3231,42 @@ def shift(self, periods=1, freq=None, axis=0, **kwds):
32313231
32323232 return self ._constructor (new_data ).__finalize__ (self )
32333233
3234+ def slice_shift (self , periods = 1 , axis = 0 , ** kwds ):
3235+ """
3236+ Equivalent to `shift` without copying data. The shifted data will
3237+ not include the dropped periods and the shifted axis will be smaller
3238+ than the original.
3239+
3240+ Parameters
3241+ ----------
3242+ periods : int
3243+ Number of periods to move, can be positive or negative
3244+
3245+ Notes
3246+ -----
3247+ While the `slice_shift` is faster than `shift`, you may pay for it
3248+ later during alignment.
3249+
3250+ Returns
3251+ -------
3252+ shifted : same type as caller
3253+ """
3254+ if periods == 0 :
3255+ return self
3256+
3257+ if periods > 0 :
3258+ vslicer = slice (None , - periods )
3259+ islicer = slice (periods , None )
3260+ else :
3261+ vslicer = slice (- periods , None )
3262+ islicer = slice (None , periods )
3263+
3264+ new_obj = self ._slice (vslicer , axis = axis )
3265+ shifted_axis = self ._get_axis (axis )[islicer ]
3266+ new_obj .set_axis (axis , shifted_axis )
3267+
3268+ return new_obj .__finalize__ (self )
3269+
32343270 def tshift (self , periods = 1 , freq = None , axis = 0 , ** kwds ):
32353271 """
32363272 Shift the time index, using the index's frequency if available
0 commit comments