Skip to content

Commit a5aed5d

Browse files
authored
DEPR: DataFrame/Series.slice_shift (#37601)
1 parent 36f026d commit a5aed5d

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

doc/source/whatsnew/v1.2.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ Deprecations
341341
- Deprecate use of strings denoting units with 'M', 'Y' or 'y' in :func:`~pandas.to_timedelta` (:issue:`36666`)
342342
- :class:`Index` methods ``&``, ``|``, and ``^`` behaving as the set operations :meth:`Index.intersection`, :meth:`Index.union`, and :meth:`Index.symmetric_difference`, respectively, are deprecated and in the future will behave as pointwise boolean operations matching :class:`Series` behavior. Use the named set methods instead (:issue:`36758`)
343343
- :meth:`Categorical.is_dtype_equal` and :meth:`CategoricalIndex.is_dtype_equal` are deprecated, will be removed in a future version (:issue:`37545`)
344+
- :meth:`Series.slice_shift` and :meth:`DataFrame.slice_shift` are deprecated, use :meth:`Series.shift` or :meth:`DataFrame.shift` instead (:issue:`37601`)
345+
344346

345347
.. ---------------------------------------------------------------------------
346348

pandas/core/generic.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -9347,10 +9347,13 @@ def shift(
93479347
def slice_shift(self: FrameOrSeries, periods: int = 1, axis=0) -> FrameOrSeries:
93489348
"""
93499349
Equivalent to `shift` without copying data.
9350-
93519350
The shifted data will not include the dropped periods and the
93529351
shifted axis will be smaller than the original.
93539352
9353+
.. deprecated:: 1.2.0
9354+
slice_shift is deprecated,
9355+
use DataFrame/Series.shift instead.
9356+
93549357
Parameters
93559358
----------
93569359
periods : int
@@ -9365,6 +9368,14 @@ def slice_shift(self: FrameOrSeries, periods: int = 1, axis=0) -> FrameOrSeries:
93659368
While the `slice_shift` is faster than `shift`, you may pay for it
93669369
later during alignment.
93679370
"""
9371+
9372+
msg = (
9373+
"The 'slice_shift' method is deprecated "
9374+
"and will be removed in a future version. "
9375+
"You can use DataFrame/Series.shift instead"
9376+
)
9377+
warnings.warn(msg, FutureWarning, stacklevel=2)
9378+
93689379
if periods == 0:
93699380
return self
93709381

pandas/tests/generic/test_finalize.py

-2
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@
424424
(pd.DataFrame, frame_data, operator.methodcaller("where", np.array([[True]]))),
425425
(pd.Series, ([1, 2],), operator.methodcaller("mask", np.array([True, False]))),
426426
(pd.DataFrame, frame_data, operator.methodcaller("mask", np.array([[True]]))),
427-
(pd.Series, ([1, 2],), operator.methodcaller("slice_shift")),
428-
(pd.DataFrame, frame_data, operator.methodcaller("slice_shift")),
429427
pytest.param(
430428
(
431429
pd.Series,

pandas/tests/generic/test_generic.py

+11
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,14 @@ def test_flags_identity(self, frame_or_series):
480480
assert s.flags is s.flags
481481
s2 = s.copy()
482482
assert s2.flags is not s.flags
483+
484+
def test_slice_shift_deprecated(self):
485+
# GH 37601
486+
df = DataFrame({"A": [1, 2, 3, 4]})
487+
s = Series([1, 2, 3, 4])
488+
489+
with tm.assert_produces_warning(FutureWarning):
490+
df["A"].slice_shift()
491+
492+
with tm.assert_produces_warning(FutureWarning):
493+
s.slice_shift()

0 commit comments

Comments
 (0)