From 6559bbf86f13d7034694fea55dedd0d47490e2c9 Mon Sep 17 00:00:00 2001 From: KalyanGokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Sun, 24 Jun 2018 18:54:21 +0530 Subject: [PATCH 1/8] Initial commit PTP --- doc/source/whatsnew/v0.24.0.txt | 2 +- pandas/core/generic.py | 7 +++++++ pandas/tests/series/test_analytics.py | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index c23ed006ff637..07a6d7e83b8c3 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -83,7 +83,7 @@ Deprecations ~~~~~~~~~~~~ - :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`). -- +- :meth:`Series.ptp` is deprecated. Use numpy.ptp instead (:issue:`18262`) - .. _whatsnew_0240.prior_deprecations: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 32f64b1d3e05c..47085656a36f9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8871,8 +8871,15 @@ def _add_series_only_operations(cls): axis_descr, name, name2 = _doc_parms(cls) def nanptp(values, axis=0, skipna=True): + """ + .. deprecated:: 0.24.0 + Use numpy.ptp instead + """ nmax = nanops.nanmax(values, axis, skipna) nmin = nanops.nanmin(values, axis, skipna) + warnings.warn("Method .ptp is deprecated and will be removed " + "in a future version. Use numpy.ptp instead.", + FutureWarning, stacklevel=2) return nmax - nmin cls.ptp = _make_stat_function( diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index b9c7b837b8b81..e47b457b30b42 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -1381,8 +1381,12 @@ def test_ptp(self): ser = Series(arr) assert np.ptp(ser) == np.ptp(arr) - # GH11163 s = Series([3, 5, np.nan, -3, 10]) + + # Xref GH18262 + with tm.assert_produces_warning(FutureWarning): + s.ptp() + # GH11163 assert s.ptp() == 13 assert pd.isna(s.ptp(skipna=False)) From d643966e51ced15276d0775c3191e3635be46988 Mon Sep 17 00:00:00 2001 From: KalyanGokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Sun, 24 Jun 2018 20:11:02 +0530 Subject: [PATCH 2/8] Updated stacklevel PTP --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 47085656a36f9..23a180aa81e65 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8879,7 +8879,7 @@ def nanptp(values, axis=0, skipna=True): nmin = nanops.nanmin(values, axis, skipna) warnings.warn("Method .ptp is deprecated and will be removed " "in a future version. Use numpy.ptp instead.", - FutureWarning, stacklevel=2) + FutureWarning, stacklevel=4) return nmax - nmin cls.ptp = _make_stat_function( From 9e72362f69a0538acb5954c5dc2e1e711a761520 Mon Sep 17 00:00:00 2001 From: KalyanGokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Sun, 24 Jun 2018 20:56:43 +0530 Subject: [PATCH 3/8] Updated issue number PTP --- doc/source/whatsnew/v0.24.0.txt | 2 +- pandas/tests/series/test_analytics.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 07a6d7e83b8c3..a9f222edbe08a 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -83,7 +83,7 @@ Deprecations ~~~~~~~~~~~~ - :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`). -- :meth:`Series.ptp` is deprecated. Use numpy.ptp instead (:issue:`18262`) +- :meth:`Series.ptp` is deprecated. Use numpy.ptp instead (:issue:`21614`) - .. _whatsnew_0240.prior_deprecations: diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index e47b457b30b42..ae22d4d262917 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -1383,7 +1383,7 @@ def test_ptp(self): s = Series([3, 5, np.nan, -3, 10]) - # Xref GH18262 + # GH21614 with tm.assert_produces_warning(FutureWarning): s.ptp() # GH11163 From 424a6709521704126ed90dcc821ebae71faa1ece Mon Sep 17 00:00:00 2001 From: KalyanGokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Mon, 25 Jun 2018 19:42:01 +0530 Subject: [PATCH 4/8] Suppressed warnings, whatsnew PTP --- doc/source/whatsnew/v0.24.0.txt | 2 +- pandas/tests/series/test_analytics.py | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index a9f222edbe08a..a8200f286fd8a 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -83,7 +83,7 @@ Deprecations ~~~~~~~~~~~~ - :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`). -- :meth:`Series.ptp` is deprecated. Use numpy.ptp instead (:issue:`21614`) +- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`) - .. _whatsnew_0240.prior_deprecations: diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index ae22d4d262917..fd8e8ec43c5c1 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -1381,33 +1381,37 @@ def test_ptp(self): ser = Series(arr) assert np.ptp(ser) == np.ptp(arr) + # GH11163 s = Series([3, 5, np.nan, -3, 10]) - # GH21614 + # Suppressed deprecation warnings in this original test for ptp with tm.assert_produces_warning(FutureWarning): - s.ptp() - # GH11163 - assert s.ptp() == 13 - assert pd.isna(s.ptp(skipna=False)) + assert s.ptp() == 13 + assert pd.isna(s.ptp(skipna=False)) mi = pd.MultiIndex.from_product([['a', 'b'], [1, 2, 3]]) s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) expected = pd.Series([6, 2], index=['a', 'b'], dtype=np.float64) - tm.assert_series_equal(s.ptp(level=0), expected) + with tm.assert_produces_warning(FutureWarning): + tm.assert_series_equal(s.ptp(level=0), expected) expected = pd.Series([np.nan, np.nan], index=['a', 'b']) - tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) + with tm.assert_produces_warning(FutureWarning): + tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) with pytest.raises(ValueError): - s.ptp(axis=1) + with tm.assert_produces_warning(FutureWarning): + s.ptp(axis=1) s = pd.Series(['a', 'b', 'c', 'd', 'e']) with pytest.raises(TypeError): - s.ptp() + with tm.assert_produces_warning(FutureWarning): + s.ptp() with pytest.raises(NotImplementedError): - s.ptp(numeric_only=True) + with tm.assert_produces_warning(FutureWarning): + s.ptp(numeric_only=True) def test_empty_timeseries_redections_return_nat(self): # covers #11245 From 0028c7c98ff89599733f18a16adc4e2133db5ded Mon Sep 17 00:00:00 2001 From: KalyanGokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Tue, 26 Jun 2018 21:41:11 +0530 Subject: [PATCH 5/8] Moved deprecation docstring, fixed tests PTP --- pandas/core/generic.py | 12 ++++++------ pandas/tests/series/test_analytics.py | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 23a180aa81e65..a3fc4bfd9d25e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8871,10 +8871,6 @@ def _add_series_only_operations(cls): axis_descr, name, name2 = _doc_parms(cls) def nanptp(values, axis=0, skipna=True): - """ - .. deprecated:: 0.24.0 - Use numpy.ptp instead - """ nmax = nanops.nanmax(values, axis, skipna) nmin = nanops.nanmin(values, axis, skipna) warnings.warn("Method .ptp is deprecated and will be removed " @@ -8884,9 +8880,13 @@ def nanptp(values, axis=0, skipna=True): cls.ptp = _make_stat_function( cls, 'ptp', name, name2, axis_descr, - """Returns the difference between the maximum value and the + """ + .. deprecated:: 0.24.0 + Use numpy.ptp instead + Returns the difference between the maximum value and the minimum value in the object. This is the equivalent of the - ``numpy.ndarray`` method ``ptp``.""", + ``numpy.ndarray`` method ``ptp``. + """, nanptp) @classmethod diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index fd8e8ec43c5c1..8afd861194c43 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -1376,6 +1376,7 @@ def test_numpy_argmax_deprecated(self): s, out=data) def test_ptp(self): + # GH21614 N = 1000 arr = np.random.randn(N) ser = Series(arr) @@ -1383,9 +1384,7 @@ def test_ptp(self): # GH11163 s = Series([3, 5, np.nan, -3, 10]) - # GH21614 - # Suppressed deprecation warnings in this original test for ptp - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert s.ptp() == 13 assert pd.isna(s.ptp(skipna=False)) @@ -1393,24 +1392,27 @@ def test_ptp(self): s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi) expected = pd.Series([6, 2], index=['a', 'b'], dtype=np.float64) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): tm.assert_series_equal(s.ptp(level=0), expected) expected = pd.Series([np.nan, np.nan], index=['a', 'b']) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) with pytest.raises(ValueError): - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): s.ptp(axis=1) s = pd.Series(['a', 'b', 'c', 'd', 'e']) with pytest.raises(TypeError): - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): s.ptp() with pytest.raises(NotImplementedError): - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): s.ptp(numeric_only=True) def test_empty_timeseries_redections_return_nat(self): From 2932a991cedef0b507d5522a9786e83dc13b5e2b Mon Sep 17 00:00:00 2001 From: Kalyan Gokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Thu, 28 Jun 2018 16:21:32 +0530 Subject: [PATCH 6/8] Update api.rst --- doc/source/api.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/api.rst b/doc/source/api.rst index f2c00d5d12031..f1e9d236c0028 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -434,7 +434,6 @@ Computations / Descriptive Stats Series.value_counts Series.compound Series.nonzero - Series.ptp Reindexing / Selection / Label manipulation From 446c8845abe7f1c3cf9ebd0078ed8d804a030f30 Mon Sep 17 00:00:00 2001 From: Kalyan Gokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Fri, 6 Jul 2018 07:48:16 +0530 Subject: [PATCH 7/8] Update generic.py --- pandas/core/generic.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 29b3d23d27175..330b5cd8256e2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8885,9 +8885,13 @@ def nanptp(values, axis=0, skipna=True): """ .. deprecated:: 0.24.0 Use numpy.ptp instead + Returns the difference between the maximum value and the minimum value in the object. This is the equivalent of the ``numpy.ndarray`` method ``ptp``. + + .. deprecated:: 0.24.0 + Use numpy.ptp instead """, nanptp) From cede49640aca5b70f02399dd3dd12c742ffd8066 Mon Sep 17 00:00:00 2001 From: Kalyan Gokhale <4734245+KalyanGokhale@users.noreply.github.com> Date: Fri, 6 Jul 2018 08:42:45 +0530 Subject: [PATCH 8/8] Update generic.py 2nd update removed duplicated deprecation comment --- pandas/core/generic.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 330b5cd8256e2..8c384e3eeea58 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8883,9 +8883,6 @@ def nanptp(values, axis=0, skipna=True): cls.ptp = _make_stat_function( cls, 'ptp', name, name2, axis_descr, """ - .. deprecated:: 0.24.0 - Use numpy.ptp instead - Returns the difference between the maximum value and the minimum value in the object. This is the equivalent of the ``numpy.ndarray`` method ``ptp``.