Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: Series.ptp() #21614

Merged
merged 9 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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:`Series.ptp` is deprecated. Use numpy.ptp instead (:issue:`21614`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put a reference to numpy.ptp as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - updated for all comments Thanks

-

.. _whatsnew_0240.prior_deprecations:
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8871,8 +8871,15 @@ def _add_series_only_operations(cls):
axis_descr, name, name2 = _doc_parms(cls)

def nanptp(values, axis=0, skipna=True):
"""
.. deprecated:: 0.24.0
Use numpy.ptp instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is the right format for the doc-str, cc @jorisvandenbossche

Copy link
Contributor Author

@KalyanGokhale KalyanGokhale Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - will wait for confirmation on right format from @jorisvandenbossche

Based on the other deprecation PRs I checked, this seemed to be the expected format - for other messages I had noted earlier I got Travis failures (example below from different PR submitted)

Check for deprecated messages without sphinx directive
pandas/core/indexes/multi.py:        DEPRECATED: to_hierarchical will be removed in a future version.
Check for deprecated messages without sphinx directive DONE
...
The command "ci/lint.sh" exited with 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the correct format. But, shouldn't this rather be in cls.ptp docstring passed to _make_stat_function below?
(didn't really check, but make sure that pd.Series.ptp? gives the correct docstring)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick check, and indeed adding the deprecation message does not update the actual docstring of Series.ptp, you need to add it to the argument passed to _make_stat_function a few lines below

"""
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(
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,12 @@ def test_ptp(self):
ser = Series(arr)
assert np.ptp(ser) == np.ptp(arr)

# GH11163
s = Series([3, 5, np.nan, -3, 10])

# GH21614
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this another method. you need to catch any warnings for calling s.ptp() anywhere in the codebase, or just call np.ptp

with tm.assert_produces_warning(FutureWarning):
s.ptp()
# GH11163
assert s.ptp() == 13
assert pd.isna(s.ptp(skipna=False))

Expand Down