-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: enforce the deprecation of the Series.argsort
NA behavior
#58232
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
Merged
mroeschke
merged 8 commits into
pandas-dev:main
from
natmokval:cln-depr-Series-argsort-NA-behavior
Jun 26, 2024
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c70529d
enforce deprecation of the Series.argsort NA behavior
natmokval 59db05e
remove comments
natmokval 6060ee7
add a note to v3.0.0
natmokval 1ad77cf
correct def argsort and tests
natmokval 6de0779
correct def argsort/tests
natmokval e65b321
fix pre-commit error
natmokval 0d05057
Merge remote-tracking branch 'upstream/main' into cln-depr-Series-arg…
mroeschke 62349d5
Restore numpy test
mroeschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,24 +20,10 @@ def test_argsort_axis(self): | |
|
||
def test_argsort_numpy(self, datetime_series): | ||
ser = datetime_series | ||
|
||
res = np.argsort(ser).values | ||
expected = np.argsort(np.array(ser)) | ||
tm.assert_numpy_array_equal(res, expected) | ||
|
||
# with missing values | ||
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 there a reason for deleting this part of the test instead of updating it? |
||
ts = ser.copy() | ||
ts[::2] = np.nan | ||
|
||
msg = "The behavior of Series.argsort in the presence of NA values" | ||
with tm.assert_produces_warning( | ||
FutureWarning, match=msg, check_stacklevel=False | ||
): | ||
result = np.argsort(ts)[1::2] | ||
expected = np.argsort(np.array(ts.dropna())) | ||
|
||
tm.assert_numpy_array_equal(result.values, expected) | ||
|
||
def test_argsort(self, datetime_series): | ||
argsorted = datetime_series.argsort() | ||
assert issubclass(argsorted.dtype.type, np.integer) | ||
|
@@ -56,10 +42,8 @@ def test_argsort_dt64(self, unit): | |
expected = Series(range(5), dtype=np.intp) | ||
tm.assert_series_equal(result, expected) | ||
|
||
msg = "The behavior of Series.argsort in the presence of NA values" | ||
with tm.assert_produces_warning(FutureWarning, match=msg): | ||
result = shifted.argsort() | ||
expected = Series(list(range(4)) + [-1], dtype=np.intp) | ||
result = shifted.argsort() | ||
expected = Series(list(range(4)) + [4], dtype=np.intp) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_argsort_stable(self): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
are NAs supposed to be sorted to the front or the end? IIUC this is putting them at the front?
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 think this is correct as the NA should be put at the end according to the deprecation message.
The fixture says
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.
Ok, I think I was confusing this with ‘rank’