From 2cb94d87d5dcb31ff685bae46fba832205c15f1a Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 13:26:06 +0100 Subject: [PATCH 1/9] depr slice_shift --- pandas/core/generic.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c90ab9cceea8c..b2664a6ef177c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9351,6 +9351,9 @@ def slice_shift(self: FrameOrSeries, periods: int = 1, axis=0) -> FrameOrSeries: 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 @@ -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 From 93ed6fb049318f1cbef70be656b60017bf380ba2 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 13:35:03 +0100 Subject: [PATCH 2/9] added test for depr --- pandas/tests/generic/test_generic.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 45601abc95fe6..cd5419a1a3ce6 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -561,3 +561,10 @@ 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 = pd.DataFrame({'A': [1, 2, 3, 4]}) + + with tm.assert_produces_warning(FutureWarning): + df['A'].slice_shift() From e4d8b674a85a586c5228a3d2ad5f9860e3c09225 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 13:38:19 +0100 Subject: [PATCH 3/9] added whatsnew entryr --- doc/source/whatsnew/v1.2.0.rst | 2 +- pandas/tests/generic/test_generic.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 45a95f6aeb2f6..54b8e1537ba07 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -341,7 +341,7 @@ 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`) .. --------------------------------------------------------------------------- diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index cd5419a1a3ce6..2b9f3adbb2a97 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -565,6 +565,10 @@ def test_flags_identity(self, as_frame): def test_slice_shift_deprecated(self): # GH 37601 df = pd.DataFrame({'A': [1, 2, 3, 4]}) + s = pd.Series([1, 2, 3, 4]) with tm.assert_produces_warning(FutureWarning): df['A'].slice_shift() + + with tm.assert_produces_warning(FutureWarning): + s.slice_shift() \ No newline at end of file From 9446191306bd0d39ed189f8212b8eb88c652dc3a Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 13:39:01 +0100 Subject: [PATCH 4/9] newline --- pandas/tests/generic/test_generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 2b9f3adbb2a97..c889d1a118ac5 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -571,4 +571,4 @@ def test_slice_shift_deprecated(self): df['A'].slice_shift() with tm.assert_produces_warning(FutureWarning): - s.slice_shift() \ No newline at end of file + s.slice_shift() From 7bda84190233c5057cd975038253d924069d3f5c Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 13:42:07 +0100 Subject: [PATCH 5/9] changes black: --- pandas/tests/generic/test_generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index c889d1a118ac5..cada8f0c769c3 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -564,11 +564,11 @@ def test_flags_identity(self, as_frame): def test_slice_shift_deprecated(self): # GH 37601 - df = pd.DataFrame({'A': [1, 2, 3, 4]}) + df = pd.DataFrame({"A": [1, 2, 3, 4]}) s = pd.Series([1, 2, 3, 4]) with tm.assert_produces_warning(FutureWarning): - df['A'].slice_shift() + df["A"].slice_shift() with tm.assert_produces_warning(FutureWarning): s.slice_shift() From 14052c6d68029df66d4e0d79193ae37e7d940801 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 14:46:57 +0100 Subject: [PATCH 6/9] remove slice_shift from test finalize --- pandas/tests/generic/test_finalize.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index d7aadda990f53..d16e854c25ed8 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -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, From 325599f5f3ea8e52d037f5926a2038058fc68351 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 14:51:15 +0100 Subject: [PATCH 7/9] blank lines whatsnew --- doc/source/whatsnew/v1.2.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 54b8e1537ba07..ea2e6784087f2 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -342,6 +342,8 @@ Deprecations - :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`) + + .. --------------------------------------------------------------------------- From b610e3173f59031f3fb22f566a814c6912eae7ed Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 15:18:44 +0100 Subject: [PATCH 8/9] fix for docstring --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b2664a6ef177c..3ccf3265c0d1a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9347,12 +9347,12 @@ 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. + slice_shift is deprecated, + use DataFrame/Series.shift instead. Parameters ---------- From fbcb7a268ae37c55f5837fe764ccff8ca3d0f10d Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 3 Nov 2020 15:40:48 +0100 Subject: [PATCH 9/9] remove pd in test --- pandas/tests/generic/test_generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index cada8f0c769c3..6eec8ef3622a8 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -564,8 +564,8 @@ def test_flags_identity(self, as_frame): def test_slice_shift_deprecated(self): # GH 37601 - df = pd.DataFrame({"A": [1, 2, 3, 4]}) - s = pd.Series([1, 2, 3, 4]) + df = DataFrame({"A": [1, 2, 3, 4]}) + s = Series([1, 2, 3, 4]) with tm.assert_produces_warning(FutureWarning): df["A"].slice_shift()