PERF: Speed up DataFrame.apply(axis=1) for ExtensionDtype columns#65097
Draft
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Draft
PERF: Speed up DataFrame.apply(axis=1) for ExtensionDtype columns#65097jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Conversation
For multi-block EA DataFrames (e.g. multiple Arrow-typed columns), series_generator now extracts scalars directly from column arrays into a reusable object-dtype Series, avoiding the expensive per-row fast_xs -> _from_sequence round-trip. Single-block EA DataFrames keep the existing fast_xs path which already preserves EA dtype. Also replace is_object_dtype(self.dtype) with self.dtype == object in _can_hold_identifiers_and_holds_name to avoid unnecessary indirection. closes pandas-dev#61747 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
series_generatornow extracts scalars directly from column arrays into a reusable object-dtype Series, avoiding the expensive per-rowfast_xs→_from_sequenceround-trip.fast_xspath which already preserves EA dtype.is_object_dtype(self.dtype)withself.dtype == objectin_can_hold_identifiers_and_holds_nameto avoid unnecessary indirection.closes #61747
Performance
500K rows, 2 columns (
int64[pyarrow]+double[pyarrow]),df.apply(lambda r: ..., axis=1):Test plan
pytest pandas/tests/apply/ -x -q— 922 passedpytest pandas/tests/extension/test_arrow.py -k apply— 240 passedpytest pandas/tests/frame/ -k apply— 7 passed🤖 Generated with Claude Code