@@ -695,22 +695,21 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
695
695
other = self ._box_pa (other )
696
696
697
697
if pa .types .is_string (pa_type ) or pa .types .is_binary (pa_type ):
698
- if op in [operator .add , roperator .radd , operator . mul , roperator . rmul ]:
698
+ if op in [operator .add , roperator .radd ]:
699
699
sep = pa .scalar ("" , type = pa_type )
700
700
if op is operator .add :
701
701
result = pc .binary_join_element_wise (self ._pa_array , other , sep )
702
702
elif op is roperator .radd :
703
703
result = pc .binary_join_element_wise (other , self ._pa_array , sep )
704
- else :
705
- if not (
706
- isinstance (other , pa .Scalar ) and pa .types .is_integer (other .type )
707
- ):
708
- raise TypeError ("Can only string multiply by an integer." )
709
- result = pc .binary_join_element_wise (
710
- * ([self ._pa_array ] * other .as_py ()), sep
711
- )
712
704
return type (self )(result )
713
-
705
+ elif op in [operator .mul , roperator .rmul ]:
706
+ result = type (self )._evaluate_binary_repeat (self ._pa_array , other )
707
+ return type (self )(result )
708
+ elif pa .types .is_integer (pa_type ) and (
709
+ pa .types .is_string (other .type ) or pa .types .is_binary (other .type )
710
+ ):
711
+ result = type (self )._evaluate_binary_repeat (other , self ._pa_array )
712
+ return type (self )(result )
714
713
if (
715
714
isinstance (other , pa .Scalar )
716
715
and pc .is_null (other ).as_py ()
@@ -726,6 +725,13 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
726
725
result = pc_func (self ._pa_array , other )
727
726
return type (self )(result )
728
727
728
+ @staticmethod
729
+ def _evaluate_binary_repeat (binary , integral ):
730
+ if not pa .types .is_integer (integral .type ):
731
+ raise TypeError ("Can only string multiply by an integer." )
732
+ pa_integral = pc .if_else (pc .less (integral , 0 ), 0 , integral )
733
+ return pc .binary_repeat (binary , pa_integral )
734
+
729
735
def _logical_method (self , other , op ):
730
736
# For integer types `^`, `|`, `&` are bitwise operators and return
731
737
# integer types. Otherwise these are boolean ops.
0 commit comments