Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: DataFrame/Series.slice_shift #37601

Merged
merged 9 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -561,3 +561,14 @@ def test_flags_identity(self, as_frame):
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()