Skip to content

Commit

Permalink
DEPR: DataFrame/Series.slice_shift (#37601)
Browse files Browse the repository at this point in the history
  • Loading branch information
erfannariman authored Nov 4, 2020
1 parent 36f026d commit a5aed5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ Deprecations
- Deprecate use of strings denoting units with 'M', 'Y' or 'y' in :func:`~pandas.to_timedelta` (:issue:`36666`)
- :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`)
- :meth:`Categorical.is_dtype_equal` and :meth:`CategoricalIndex.is_dtype_equal` are deprecated, will be removed in a future version (:issue:`37545`)
- :meth:`Series.slice_shift` and :meth:`DataFrame.slice_shift` are deprecated, use :meth:`Series.shift` or :meth:`DataFrame.shift` instead (:issue:`37601`)


.. ---------------------------------------------------------------------------
Expand Down
13 changes: 12 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9347,10 +9347,13 @@ def shift(
def slice_shift(self: FrameOrSeries, periods: int = 1, axis=0) -> FrameOrSeries:
"""
Equivalent to `shift` without copying data.
The shifted data will not include the dropped periods and the
shifted axis will be smaller than the original.
.. deprecated:: 1.2.0
slice_shift is deprecated,
use DataFrame/Series.shift instead.
Parameters
----------
periods : int
Expand All @@ -9365,6 +9368,14 @@ def slice_shift(self: FrameOrSeries, periods: int = 1, axis=0) -> FrameOrSeries:
While the `slice_shift` is faster than `shift`, you may pay for it
later during alignment.
"""

msg = (
"The 'slice_shift' method is deprecated "
"and will be removed in a future version. "
"You can use DataFrame/Series.shift instead"
)
warnings.warn(msg, FutureWarning, stacklevel=2)

if periods == 0:
return self

Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,6 @@
(pd.DataFrame, frame_data, operator.methodcaller("where", np.array([[True]]))),
(pd.Series, ([1, 2],), operator.methodcaller("mask", np.array([True, False]))),
(pd.DataFrame, frame_data, operator.methodcaller("mask", np.array([[True]]))),
(pd.Series, ([1, 2],), operator.methodcaller("slice_shift")),
(pd.DataFrame, frame_data, operator.methodcaller("slice_shift")),
pytest.param(
(
pd.Series,
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,14 @@ def test_flags_identity(self, frame_or_series):
assert s.flags is s.flags
s2 = s.copy()
assert s2.flags is not s.flags

def test_slice_shift_deprecated(self):
# GH 37601
df = DataFrame({"A": [1, 2, 3, 4]})
s = Series([1, 2, 3, 4])

with tm.assert_produces_warning(FutureWarning):
df["A"].slice_shift()

with tm.assert_produces_warning(FutureWarning):
s.slice_shift()

0 comments on commit a5aed5d

Please sign in to comment.