ENH: allow StringDType to use the sort paths in isin - #32693
Conversation
|
Just curious, how does this stack up against the PR you closed? Cause the speedups you're showing here are amazing. |
|
I'm not sure. Probably better because we're relying on C code rather than re-implementing rules for StringDType operations in Python. |
|
I just quickly measured and they're actually about the same. The improvement is mostly algorithmic: the sorting path is O(nlogn) and the slow object path is O(N^2). But thank you for asking me to do this exercise because I see some marginal performance improvements. |
| {"_has_nan_na", T_BOOL, | ||
| offsetof(PyArray_StringDTypeObject, has_nan_na), READONLY, | ||
| "Whether the missing value object has NaN-like semantics"}, | ||
| {"_has_string_na", T_BOOL, |
There was a problem hiding this comment.
This is not used atm. Do you anticipate future use?
There was a problem hiding this comment.
I just pushed another commit that uses the new private attributes (including this one) in a few more spots. Mostly in tests.
MaanasArora
left a comment
There was a problem hiding this comment.
Thanks @ngoldbaum! This looks good to me, just one question and one test suggestion.
MaanasArora
left a comment
There was a problem hiding this comment.
Thank you, LGTM! The speedups are really great given how cleanly contained the workarounds are.
PR summary
Fixes #32161. Supersedes #32217.
This follows up on recent improvements to StringDType (in particular #32563 and #32464) to enable substantial performance improvements for
isin. Also adds more tests forisinin theStringDTypetests.Tests and benchmarks ran on an M1 MacBook Air using Python 3.14. The
pandas.NAcase uses pandas 3.0.5.main)Nonenp.nan"NA"object()pandas.NAFor
pandas.NA, the patch also fixes an error and correctly reports missing entries as non-matches. All returned results were checked against the expected membership mask.Each baseline was measured once; patched timings are the best of three runs. Input creation is excluded from the timings. Reproduce with
repeats=1on the baseline andrepeats=3on the patched build:AI Disclosure
I used an AI to iterate on this.