Skip to content

Commit b5f7984

Browse files
authored
PERF: Series.add for pyarrow string/binary dtypes (#53150)
* PERF: Series.add for pyarrow string/binary dtypes * whatsnew
1 parent 7d59f55 commit b5f7984

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ Performance improvements
289289
- Performance improvement in :func:`concat` when ``axis=1`` and objects have different indexes (:issue:`52541`)
290290
- Performance improvement in :meth:`.DataFrameGroupBy.groups` (:issue:`53088`)
291291
- Performance improvement in :meth:`DataFrame.loc` when selecting rows and columns (:issue:`53014`)
292+
- Performance improvement in :meth:`Series.add` for pyarrow string and binary dtypes (:issue:`53150`)
292293
- Performance improvement in :meth:`Series.corr` and :meth:`Series.cov` for extension dtypes (:issue:`52502`)
293294
- Performance improvement in :meth:`Series.to_numpy` when dtype is a numpy float dtype and ``na_value`` is ``np.nan`` (:issue:`52430`)
294295
- Performance improvement in :meth:`~arrays.ArrowExtensionArray.to_numpy` (:issue:`52525`)

pandas/core/arrays/arrow/array.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -495,22 +495,13 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
495495
operator.add,
496496
roperator.radd,
497497
]:
498-
length = self._pa_array.length()
499-
500-
seps: list[str] | list[bytes]
501-
if pa.types.is_string(pa_type):
502-
seps = [""] * length
503-
else:
504-
seps = [b""] * length
505-
506-
if is_scalar(other):
507-
other = [other] * length
508-
elif isinstance(other, type(self)):
498+
sep = pa.scalar("", type=pa_type)
499+
if isinstance(other, type(self)):
509500
other = other._pa_array
510501
if op is operator.add:
511-
result = pc.binary_join_element_wise(self._pa_array, other, seps)
502+
result = pc.binary_join_element_wise(self._pa_array, other, sep)
512503
else:
513-
result = pc.binary_join_element_wise(other, self._pa_array, seps)
504+
result = pc.binary_join_element_wise(other, self._pa_array, sep)
514505
return type(self)(result)
515506

516507
pc_func = arrow_funcs[op.__name__]

0 commit comments

Comments
 (0)