@@ -693,22 +693,31 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
693
693
other = self ._box_pa (other )
694
694
695
695
if pa .types .is_string (pa_type ) or pa .types .is_binary (pa_type ):
696
- if op in [operator .add , roperator .radd , operator . mul , roperator . rmul ]:
696
+ if op in [operator .add , roperator .radd ]:
697
697
sep = pa .scalar ("" , type = pa_type )
698
698
if op is operator .add :
699
699
result = pc .binary_join_element_wise (self ._pa_array , other , sep )
700
700
elif op is roperator .radd :
701
701
result = pc .binary_join_element_wise (other , self ._pa_array , sep )
702
- else :
703
- if not (
704
- isinstance (other , pa .Scalar ) and pa .types .is_integer (other .type )
705
- ):
706
- raise TypeError ("Can only string multiply by an integer." )
707
- result = pc .binary_join_element_wise (
708
- * ([self ._pa_array ] * other .as_py ()), sep
709
- )
710
702
return type (self )(result )
711
-
703
+ elif op in [operator .mul , roperator .rmul ]:
704
+ binary = self ._pa_array
705
+ integral = other
706
+ if not pa .types .is_integer (integral .type ):
707
+ raise TypeError ("Can only string multiply by an integer." )
708
+ pa_integral = pc .if_else (pc .less (integral , 0 ), 0 , integral )
709
+ result = pc .binary_repeat (binary , pa_integral )
710
+ return type (self )(result )
711
+ elif (
712
+ pa .types .is_string (other .type ) or pa .types .is_binary (other .type )
713
+ ) and op in [operator .mul , roperator .rmul ]:
714
+ binary = other
715
+ integral = self ._pa_array
716
+ if not pa .types .is_integer (integral .type ):
717
+ raise TypeError ("Can only string multiply by an integer." )
718
+ pa_integral = pc .if_else (pc .less (integral , 0 ), 0 , integral )
719
+ result = pc .binary_repeat (binary , pa_integral )
720
+ return type (self )(result )
712
721
if (
713
722
isinstance (other , pa .Scalar )
714
723
and pc .is_null (other ).as_py ()
0 commit comments