Skip to content

Commit 530aced

Browse files
jbrockmendelAlexKirko
authored andcommitted
DEPR: remove ptp (pandas-dev#30458)
1 parent b14a24f commit 530aced

File tree

4 files changed

+8
-71
lines changed

4 files changed

+8
-71
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
569569
- A tuple passed to :meth:`DataFrame.groupby` is now exclusively treated as a single key (:issue:`18314`)
570570
- Removed the previously deprecated :meth:`Index.contains`, use ``key in index`` instead (:issue:`30103`)
571571
- Addition and subtraction of ``int`` or integer-arrays is no longer allowed in :class:`Timestamp`, :class:`DatetimeIndex`, :class:`TimedeltaIndex`, use ``obj + n * obj.freq`` instead of ``obj + n`` (:issue:`22535`)
572+
- Removed :meth:`Series.ptp` (:issue:`21614`)
572573
- Removed :meth:`Series.from_array` (:issue:`18258`)
573574
- Removed :meth:`DataFrame.from_items` (:issue:`18458`)
574575
- Removed :meth:`DataFrame.as_matrix`, :meth:`Series.as_matrix` (:issue:`18458`)

pandas/core/generic.py

+6-35
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from pandas._config import config
3030

31-
from pandas._libs import Timestamp, iNaT, properties
31+
from pandas._libs import Timestamp, iNaT, lib, properties
3232
from pandas._typing import Dtype, FilePathOrBuffer, FrameOrSeries, JSONSerializable
3333
from pandas.compat import set_function_name
3434
from pandas.compat._optional import import_optional_dependency
@@ -1920,6 +1920,11 @@ def __array__(self, dtype=None):
19201920
return com.values_from_object(self)
19211921

19221922
def __array_wrap__(self, result, context=None):
1923+
result = lib.item_from_zerodim(result)
1924+
if is_scalar(result):
1925+
# e.g. we get here with np.ptp(series)
1926+
# ptp also requires the item_from_zerodim
1927+
return result
19231928
d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False)
19241929
return self._constructor(result, **d).__finalize__(self)
19251930

@@ -10166,40 +10171,6 @@ def mad(self, axis=None, skipna=None, level=None):
1016610171
_min_examples,
1016710172
)
1016810173

10169-
@classmethod
10170-
def _add_series_only_operations(cls):
10171-
"""
10172-
Add the series only operations to the cls; evaluate the doc
10173-
strings again.
10174-
"""
10175-
10176-
axis_descr, name, name2 = _doc_parms(cls)
10177-
10178-
def nanptp(values, axis=0, skipna=True):
10179-
nmax = nanops.nanmax(values, axis, skipna)
10180-
nmin = nanops.nanmin(values, axis, skipna)
10181-
warnings.warn(
10182-
"Method .ptp is deprecated and will be removed "
10183-
"in a future version. Use numpy.ptp instead.",
10184-
FutureWarning,
10185-
stacklevel=4,
10186-
)
10187-
return nmax - nmin
10188-
10189-
cls.ptp = _make_stat_function(
10190-
cls,
10191-
"ptp",
10192-
name,
10193-
name2,
10194-
axis_descr,
10195-
"""Return the difference between the min and max value.
10196-
\n.. deprecated:: 0.24.0 Use numpy.ptp instead
10197-
\nReturn the difference between the maximum value and the
10198-
minimum value in the object. This is the equivalent of the
10199-
``numpy.ndarray`` method ``ptp``.""",
10200-
nanptp,
10201-
)
10202-
1020310174
@classmethod
1020410175
def _add_series_or_dataframe_operations(cls):
1020510176
"""

pandas/core/series.py

-1
Original file line numberDiff line numberDiff line change
@@ -4390,7 +4390,6 @@ def to_period(self, freq=None, copy=True):
43904390
["index"], docs={"index": "The index (axis labels) of the Series."},
43914391
)
43924392
Series._add_numeric_operations()
4393-
Series._add_series_only_operations()
43944393
Series._add_series_or_dataframe_operations()
43954394

43964395
# Add arithmetic!

pandas/tests/series/test_analytics.py

+1-35
Original file line numberDiff line numberDiff line change
@@ -198,41 +198,7 @@ def test_ptp(self):
198198
N = 1000
199199
arr = np.random.randn(N)
200200
ser = Series(arr)
201-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
202-
assert np.ptp(ser) == np.ptp(arr)
203-
204-
# GH11163
205-
s = Series([3, 5, np.nan, -3, 10])
206-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
207-
assert s.ptp() == 13
208-
assert pd.isna(s.ptp(skipna=False))
209-
210-
mi = pd.MultiIndex.from_product([["a", "b"], [1, 2, 3]])
211-
s = pd.Series([1, np.nan, 7, 3, 5, np.nan], index=mi)
212-
213-
expected = pd.Series([6, 2], index=["a", "b"], dtype=np.float64)
214-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
215-
tm.assert_series_equal(s.ptp(level=0), expected)
216-
217-
expected = pd.Series([np.nan, np.nan], index=["a", "b"])
218-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
219-
tm.assert_series_equal(s.ptp(level=0, skipna=False), expected)
220-
221-
msg = "No axis named 1 for object type <class 'pandas.core.series.Series'>"
222-
with pytest.raises(ValueError, match=msg):
223-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
224-
s.ptp(axis=1)
225-
226-
s = pd.Series(["a", "b", "c", "d", "e"])
227-
msg = r"unsupported operand type\(s\) for -: 'str' and 'str'"
228-
with pytest.raises(TypeError, match=msg):
229-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
230-
s.ptp()
231-
232-
msg = r"Series\.ptp does not implement numeric_only\."
233-
with pytest.raises(NotImplementedError, match=msg):
234-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
235-
s.ptp(numeric_only=True)
201+
assert np.ptp(ser) == np.ptp(arr)
236202

237203
def test_repeat(self):
238204
s = Series(np.random.randn(3), index=["a", "b", "c"])

0 commit comments

Comments
 (0)