Skip to content

PERF: DataFrame.first_valid_index/last_valid_index for EA dtypes #51549

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
merged 5 commits into from
Feb 23, 2023

Conversation

lukemanley
Copy link
Member

ASV added:

       before                after    ratio
-      21.6±0.1ms          484±9μs     0.02  frame_methods.FindValidIndex.time_last_valid_index('float64[pyarrow]')
-      21.6±0.3ms          427±3μs     0.02  frame_methods.FindValidIndex.time_first_valid_index('float64[pyarrow]')
-      17.0±0.5ms          167±4μs     0.01  frame_methods.FindValidIndex.time_last_valid_index('Float64')
-      16.8±0.2ms          132±2μs     0.01  frame_methods.FindValidIndex.time_first_valid_index('Float64')

@lukemanley lukemanley added ExtensionArray Extending pandas with custom dtypes or arrays. Performance Memory or execution speed performance labels Feb 22, 2023
@jbrockmendel
Copy link
Member

wow thats a huge difference. is it all in the len(values) or something?

@lukemanley
Copy link
Member Author

lukemanley commented Feb 22, 2023

wow thats a huge difference. is it all in the len(values) or something?

self._values on a multi-column EA-backed frame converts to an object dtype ndarray. This avoids going through the object dtype conversion.

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice!

This is basically the same as with MultiIndex._values?

@phofl phofl added this to the 2.1 milestone Feb 22, 2023
@lukemanley
Copy link
Member Author

This is basically the same as with MultiIndex._values?

similar in the sense they're both expensive conversions through object dtype. MultiIndex._values has the additional overhead of wrapping in tuples.

@phofl
Copy link
Member

phofl commented Feb 22, 2023

Yep, thx, that's what I was thinking

@phofl
Copy link
Member

phofl commented Feb 23, 2023

Thx @lukemanley

@phofl phofl merged commit 65bca65 into pandas-dev:main Feb 23, 2023
@lukemanley lukemanley deleted the perf-first-valid-index branch March 17, 2023 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants