diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4f11c3c88176e..6f787ed9179bd 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10184,42 +10184,42 @@ 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." - "if you are already using numpy.ptp and still getting this message," - "please call to_numpy() to avoid this message in future calls." - "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", - 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_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." + # "if you are already using numpy.ptp and still getting this message," + # "please call to_numpy() to avoid this message in future calls." + # "For example: np.ptp(pd.Series([1, 2, 3]).to_numpy())", + # 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..392d3cf33cc2b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4390,7 +4390,7 @@ 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_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 0eb4e8a6cfdf3..c474f00e52c35 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -861,37 +861,37 @@ def test_ptp(self): 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) + # 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) def test_repeat(self): s = Series(np.random.randn(3), index=["a", "b", "c"])