@@ -681,7 +681,12 @@ def __invert__(self) -> Self:
681
681
return type (self )(pc .invert (self ._pa_array ))
682
682
683
683
def __neg__ (self ) -> Self :
684
- return type (self )(pc .negate_checked (self ._pa_array ))
684
+ try :
685
+ return type (self )(pc .negate_checked (self ._pa_array ))
686
+ except pa .ArrowNotImplementedError as err :
687
+ raise TypeError (
688
+ f"unary '-' not supported for dtype '{ self .dtype } '"
689
+ ) from err
685
690
686
691
def __pos__ (self ) -> Self :
687
692
return type (self )(self ._pa_array )
@@ -736,8 +741,19 @@ def _cmp_method(self, other, op) -> ArrowExtensionArray:
736
741
)
737
742
return ArrowExtensionArray (result )
738
743
744
+ def _op_method_error_message (self , other , op ) -> str :
745
+ if hasattr (other , "dtype" ):
746
+ other_type = f"dtype '{ other .dtype } '"
747
+ else :
748
+ other_type = f"object of type { type (other )} "
749
+ return (
750
+ f"operation '{ op .__name__ } ' not supported for "
751
+ f"dtype '{ self .dtype } ' with { other_type } "
752
+ )
753
+
739
754
def _evaluate_op_method (self , other , op , arrow_funcs ) -> Self :
740
755
pa_type = self ._pa_array .type
756
+ other_original = other
741
757
other = self ._box_pa (other )
742
758
743
759
if (
@@ -747,10 +763,15 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
747
763
):
748
764
if op in [operator .add , roperator .radd ]:
749
765
sep = pa .scalar ("" , type = pa_type )
750
- if op is operator .add :
751
- result = pc .binary_join_element_wise (self ._pa_array , other , sep )
752
- elif op is roperator .radd :
753
- result = pc .binary_join_element_wise (other , self ._pa_array , sep )
766
+ try :
767
+ if op is operator .add :
768
+ result = pc .binary_join_element_wise (self ._pa_array , other , sep )
769
+ elif op is roperator .radd :
770
+ result = pc .binary_join_element_wise (other , self ._pa_array , sep )
771
+ except pa .ArrowNotImplementedError as err :
772
+ raise TypeError (
773
+ self ._op_method_error_message (other_original , op )
774
+ ) from err
754
775
return type (self )(result )
755
776
elif op in [operator .mul , roperator .rmul ]:
756
777
binary = self ._pa_array
@@ -782,9 +803,14 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
782
803
783
804
pc_func = arrow_funcs [op .__name__ ]
784
805
if pc_func is NotImplemented :
806
+ if pa .types .is_string (pa_type ) or pa .types .is_large_string (pa_type ):
807
+ raise TypeError (self ._op_method_error_message (other_original , op ))
785
808
raise NotImplementedError (f"{ op .__name__ } not implemented." )
786
809
787
- result = pc_func (self ._pa_array , other )
810
+ try :
811
+ result = pc_func (self ._pa_array , other )
812
+ except pa .ArrowNotImplementedError as err :
813
+ raise TypeError (self ._op_method_error_message (other_original , op )) from err
788
814
return type (self )(result )
789
815
790
816
def _logical_method (self , other , op ) -> Self :
0 commit comments