-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Changes from 6 commits
6559bbf
d643966
9e72362
424a670
0028c7c
c25ea13
2932a99
446c884
cede496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. tm.assert_series_equal(s.ptp(level=0), expected) without it, this test was failing with 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 |
||
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 | ||
|
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