Skip to content

Commit d21ad1a

Browse files
authored
PERF: avoid object-dtype path in ArrowEA._explode (#61786)
* PERF: avoid object-dtype path in ArrowEA._explode * typo fixup
1 parent ff8a607 commit d21ad1a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,8 +1908,10 @@ def _explode(self):
19081908
fill_value = pa.scalar([None], type=self._pa_array.type)
19091909
mask = counts == 0
19101910
if mask.any():
1911-
values = values.copy()
1912-
values[mask] = fill_value
1911+
# pc.if_else here is similar to `values[mask] = fill_value`
1912+
# but this avoids an object-dtype round-trip.
1913+
pa_values = pc.if_else(~mask, values._pa_array, fill_value)
1914+
values = type(self)(pa_values)
19131915
counts = counts.copy()
19141916
counts[mask] = 1
19151917
values = values.fillna(fill_value)

0 commit comments

Comments
 (0)