Skip to content

Commit f8977a4

Browse files
KalyanGokhalejorisvandenbossche
authored andcommitted
DEPR: Series.ptp() (#21614)
1 parent 04caa56 commit f8977a4

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

doc/source/api.rst

-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ Computations / Descriptive Stats
435435
Series.value_counts
436436
Series.compound
437437
Series.nonzero
438-
Series.ptp
439438

440439

441440
Reindexing / Selection / Label manipulation

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ Deprecations
239239

240240
- :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`).
241241
- :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`)
242+
- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`)
242243
-
243244

244245
.. _whatsnew_0240.prior_deprecations:

pandas/core/generic.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -8876,13 +8876,21 @@ def _add_series_only_operations(cls):
88768876
def nanptp(values, axis=0, skipna=True):
88778877
nmax = nanops.nanmax(values, axis, skipna)
88788878
nmin = nanops.nanmin(values, axis, skipna)
8879+
warnings.warn("Method .ptp is deprecated and will be removed "
8880+
"in a future version. Use numpy.ptp instead.",
8881+
FutureWarning, stacklevel=4)
88798882
return nmax - nmin
88808883

88818884
cls.ptp = _make_stat_function(
88828885
cls, 'ptp', name, name2, axis_descr,
8883-
"""Returns the difference between the maximum value and the
8886+
"""
8887+
Returns the difference between the maximum value and the
88848888
minimum value in the object. This is the equivalent of the
8885-
``numpy.ndarray`` method ``ptp``.""",
8889+
``numpy.ndarray`` method ``ptp``.
8890+
8891+
.. deprecated:: 0.24.0
8892+
Use numpy.ptp instead
8893+
""",
88868894
nanptp)
88878895

88888896
@classmethod

pandas/tests/series/test_analytics.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -1395,34 +1395,44 @@ def test_numpy_argmax_deprecated(self):
13951395
s, out=data)
13961396

13971397
def test_ptp(self):
1398+
# GH21614
13981399
N = 1000
13991400
arr = np.random.randn(N)
14001401
ser = Series(arr)
14011402
assert np.ptp(ser) == np.ptp(arr)
14021403

14031404
# GH11163
14041405
s = Series([3, 5, np.nan, -3, 10])
1405-
assert s.ptp() == 13
1406-
assert pd.isna(s.ptp(skipna=False))
1406+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1407+
assert s.ptp() == 13
1408+
assert pd.isna(s.ptp(skipna=False))
14071409

14081410
mi = pd.MultiIndex.from_product([['a', 'b'], [1, 2, 3]])
14091411
s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi)
14101412

14111413
expected = pd.Series([6, 2], index=['a', 'b'], dtype=np.float64)
1412-
tm.assert_series_equal(s.ptp(level=0), expected)
1414+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1415+
tm.assert_series_equal(s.ptp(level=0), expected)
14131416

14141417
expected = pd.Series([np.nan, np.nan], index=['a', 'b'])
1415-
tm.assert_series_equal(s.ptp(level=0, skipna=False), expected)
1418+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1419+
tm.assert_series_equal(s.ptp(level=0, skipna=False), expected)
14161420

14171421
with pytest.raises(ValueError):
1418-
s.ptp(axis=1)
1422+
with tm.assert_produces_warning(FutureWarning,
1423+
check_stacklevel=False):
1424+
s.ptp(axis=1)
14191425

14201426
s = pd.Series(['a', 'b', 'c', 'd', 'e'])
14211427
with pytest.raises(TypeError):
1422-
s.ptp()
1428+
with tm.assert_produces_warning(FutureWarning,
1429+
check_stacklevel=False):
1430+
s.ptp()
14231431

14241432
with pytest.raises(NotImplementedError):
1425-
s.ptp(numeric_only=True)
1433+
with tm.assert_produces_warning(FutureWarning,
1434+
check_stacklevel=False):
1435+
s.ptp(numeric_only=True)
14261436

14271437
def test_empty_timeseries_redections_return_nat(self):
14281438
# covers #11245

0 commit comments

Comments
 (0)