-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
DEPR: Series.ptp() #21614
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21614 +/- ##
==========================================
+ Coverage 91.9% 91.93% +0.03%
==========================================
Files 154 159 +5
Lines 49562 49734 +172
==========================================
+ Hits 45549 45722 +173
+ Misses 4013 4012 -1
Continue to review full report at Codecov.
|
doc/source/whatsnew/v0.24.0.txt
Outdated
@@ -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`) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
pandas/core/generic.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
s = Series([3, 5, np.nan, -3, 10]) | ||
|
||
# GH21614 |
There was a problem hiding this comment.
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
pandas/core/generic.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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
Thanks @jorisvandenbossche have moved the docstring to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove from doc/api.rst as well, otherwise lgtm.
@jreback thanks - done - all green |
lgtm. @jorisvandenbossche |
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the check_stacklevel=False
needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - it seems to be required, not for this particular check(i.e. assert s.ptp() == 13
), but for e.g. the following
tm.assert_series_equal(s.ptp(level=0), expected)
without it, this test was failing with AssertionError: Warning not set with correct stacklevel.
I also did trial-and-error with different stacklevels, without any success (though stacklevel=4 seems to be appropriate for where the warning is raised)
Any suggestions? Thanks
pandas/core/generic.py
Outdated
""" | ||
.. deprecated:: 0.24.0 | ||
Use numpy.ptp instead | ||
Returns the difference between the maximum value and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a blank line above this one. Can you also put the deprecated part below the text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - Done - let me know if the deprecated note below main text needs any edits, have also added the line Use numpy.ptp instead
again
``numpy.ndarray`` method ``ptp``.""", | ||
``numpy.ndarray`` method ``ptp``. | ||
|
||
.. deprecated:: 0.24.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm this is duplicated here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is based on comment from @jorisvandenbossche
Can you also put the deprecated part below the text?
- waiting for his reply if the edit was as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad - misinterpreted his review and duplicated in hurry - fixing now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done thanks
2nd update removed duplicated deprecation comment
Just curious why Series.ptp() was deprecated? It was very useful shorthand for finding the period range of a DateTime column. df.DATE_TIME.ptp()
Timedelta('56 days 01:04:15') |
sure but it’s just one more method to maintain |
xref #18262
git diff upstream/master -u -- "*.py" | flake8 --diff