From 530acede8924ae74e42566ccdae8f7ca5b23bfe4 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 25 Dec 2019 15:51:16 -0800 Subject: [PATCH] DEPR: remove ptp (#30458) --- doc/source/whatsnew/v1.0.0.rst | 1 + pandas/core/generic.py | 41 ++++----------------------- pandas/core/series.py | 1 - pandas/tests/series/test_analytics.py | 36 +---------------------- 4 files changed, 8 insertions(+), 71 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 8d23914889329..0c41ed6a27a68 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -569,6 +569,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - A tuple passed to :meth:`DataFrame.groupby` is now exclusively treated as a single key (:issue:`18314`) - Removed the previously deprecated :meth:`Index.contains`, use ``key in index`` instead (:issue:`30103`) - 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`) +- Removed :meth:`Series.ptp` (:issue:`21614`) - Removed :meth:`Series.from_array` (:issue:`18258`) - Removed :meth:`DataFrame.from_items` (:issue:`18458`) - Removed :meth:`DataFrame.as_matrix`, :meth:`Series.as_matrix` (:issue:`18458`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 66c4d09d0027a..f846d5883a8b5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -28,7 +28,7 @@ from pandas._config import config -from pandas._libs import Timestamp, iNaT, properties +from pandas._libs import Timestamp, iNaT, lib, properties from pandas._typing import Dtype, FilePathOrBuffer, FrameOrSeries, JSONSerializable from pandas.compat import set_function_name from pandas.compat._optional import import_optional_dependency @@ -1920,6 +1920,11 @@ def __array__(self, dtype=None): return com.values_from_object(self) def __array_wrap__(self, result, context=None): + result = lib.item_from_zerodim(result) + if is_scalar(result): + # e.g. we get here with np.ptp(series) + # ptp also requires the item_from_zerodim + return result d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False) return self._constructor(result, **d).__finalize__(self) @@ -10166,40 +10171,6 @@ def mad(self, axis=None, skipna=None, level=None): _min_examples, ) - @classmethod - def _add_series_only_operations(cls): - """ - Add the series only operations to the cls; evaluate the doc - strings again. - """ - - axis_descr, name, name2 = _doc_parms(cls) - - def nanptp(values, axis=0, skipna=True): - 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=4, - ) - return nmax - nmin - - cls.ptp = _make_stat_function( - cls, - "ptp", - name, - name2, - axis_descr, - """Return the difference between the min and max value. - \n.. deprecated:: 0.24.0 Use numpy.ptp instead - \nReturn the difference between the maximum value and the - minimum value in the object. This is the equivalent of the - ``numpy.ndarray`` method ``ptp``.""", - nanptp, - ) - @classmethod def _add_series_or_dataframe_operations(cls): """ diff --git a/pandas/core/series.py b/pandas/core/series.py index 54c163330e6ee..4ed903d41a7a0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4390,7 +4390,6 @@ def to_period(self, freq=None, copy=True): ["index"], docs={"index": "The index (axis labels) of the Series."}, ) Series._add_numeric_operations() -Series._add_series_only_operations() Series._add_series_or_dataframe_operations() # Add arithmetic! diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 17cf307a04d7f..0c3c14af5fc1a 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -198,41 +198,7 @@ def test_ptp(self): N = 1000 arr = np.random.randn(N) ser = Series(arr) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert np.ptp(ser) == np.ptp(arr) - - # GH11163 - s = Series([3, 5, np.nan, -3, 10]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=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) - 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, check_stacklevel=False): - tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) - - msg = "No axis named 1 for object type " - with pytest.raises(ValueError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp(axis=1) - - s = pd.Series(["a", "b", "c", "d", "e"]) - msg = r"unsupported operand type\(s\) for -: 'str' and 'str'" - with pytest.raises(TypeError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp() - - msg = r"Series\.ptp does not implement numeric_only\." - with pytest.raises(NotImplementedError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s.ptp(numeric_only=True) + assert np.ptp(ser) == np.ptp(arr) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"])