Skip to content

PERF: avoid object-dtype path in ArrowEA._explode #61786

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 2 commits into from
Jul 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1908,8 +1908,10 @@ def _explode(self):
fill_value = pa.scalar([None], type=self._pa_array.type)
mask = counts == 0
if mask.any():
values = values.copy()
values[mask] = fill_value
# pc.if_else here is similar to `values[mask] = fill_value`
# but this avoids an object-dtype round-trip.
pa_values = pc.if_else(~mask, values._pa_array, fill_value)
values = type(self)(pa_values)
counts = counts.copy()
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated, but this need to be a copy (since it comes from a computed operation already)?

Copy link
Member Author

Choose a reason for hiding this comment

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

i dont see why it would. will remove it in my next "assorted cleanups" branch

counts[mask] = 1
values = values.fillna(fill_value)
Expand Down
Loading