Skip to content

Commit

Permalink
DEPR: Series.ptp() (pandas-dev#21614)
Browse files Browse the repository at this point in the history
  • Loading branch information
KalyanGokhale authored and victor committed Sep 30, 2018
1 parent 28ff738 commit bd8607d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
1 change: 0 additions & 1 deletion doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ Computations / Descriptive Stats
Series.value_counts
Series.compound
Series.nonzero
Series.ptp


Reindexing / Selection / Label manipulation
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,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:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`)
- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`)
-

.. _whatsnew_0240.prior_deprecations:
Expand Down
12 changes: 10 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8876,13 +8876,21 @@ def _add_series_only_operations(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,
"""Returns the difference between the maximum value and the
"""
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``.
.. deprecated:: 0.24.0
Use numpy.ptp instead
""",
nanptp)

@classmethod
Expand Down
24 changes: 17 additions & 7 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,34 +1395,44 @@ def test_numpy_argmax_deprecated(self):
s, out=data)

def test_ptp(self):
# GH21614
N = 1000
arr = np.random.randn(N)
ser = Series(arr)
assert np.ptp(ser) == np.ptp(arr)

# GH11163
s = Series([3, 5, np.nan, -3, 10])
assert s.ptp() == 13
assert pd.isna(s.ptp(skipna=False))
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)
tm.assert_series_equal(s.ptp(level=0), expected)
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'])
tm.assert_series_equal(s.ptp(level=0, skipna=False), expected)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
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,
check_stacklevel=False):
s.ptp(axis=1)

s = pd.Series(['a', 'b', 'c', 'd', 'e'])
with pytest.raises(TypeError):
s.ptp()
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
s.ptp()

with pytest.raises(NotImplementedError):
s.ptp(numeric_only=True)
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
s.ptp(numeric_only=True)

def test_empty_timeseries_redections_return_nat(self):
# covers #11245
Expand Down

0 comments on commit bd8607d

Please sign in to comment.