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