-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG/PERF: use lexsort_indexer in MultiIndex.argsort #48495
BUG/PERF: use lexsort_indexer in MultiIndex.argsort #48495
Conversation
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.
Special casing only numpy dtypes makes it ugly, correct?
That was my thinking. DataFrame.sort_index uses the same approach with lexsort_indexer and does not special case numpy dtypes. |
Ok, sounds reasonable |
Can you merge main to get ci green? |
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.
Would be good to have a test that calls MultiIndex.argsort
directly
added an explicit argsort test |
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.
LGTM. Merge when ready @phofl
Just merged the other pr. Could you maybe run asvs once more? Union has a bunch of code paths, want to see if this is affected |
I don’t think this touches union. Were you thinking of #48504 ? |
This is now failing following the merge of #48505. The test failing is Here is an example:
With this PR the behavior will be consistent as we'll be sending both through lexsort_indexer. I've removed the expectation for a RunTimeWarning from the test. Let me know if that doesn't make sense. |
@@ -280,3 +281,24 @@ def test_remove_unused_levels_with_nan(): | |||
result = idx.levels | |||
expected = FrozenList([["a", np.nan], [4]]) | |||
assert str(result) == str(expected) | |||
|
|||
|
|||
def test_sort_values_nan(): |
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 add gh refs
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.
Added refs
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.
Other tests as well please
@phofl - gentle ping. I think this is ready. |
thx. @lukemanley |
doc/source/whatsnew/v1.6.0.rst
file if fixing a bug or adding a new feature.cc: @phofl, @mroeschke - follow on to #48406
Had I been aware of lexsort_indexer I would have used that in #48406. Using lexsort_indexer handles
pd.NA
(np.lexsort raises) and has better perf for nullable types (Int64 on par with int64).While the perf for non-nullable types (e.g. int64) suffers a bit, this is still much faster than prior to #48406.