@@ -676,7 +676,12 @@ def __invert__(self) -> Self:
676
676
return type (self )(pc .invert (self ._pa_array ))
677
677
678
678
def __neg__ (self ) -> Self :
679
- return type (self )(pc .negate_checked (self ._pa_array ))
679
+ try :
680
+ return type (self )(pc .negate_checked (self ._pa_array ))
681
+ except pa .ArrowNotImplementedError as err :
682
+ raise TypeError (
683
+ f"unary '-' not supported for dtype '{ self .dtype } '"
684
+ ) from err
680
685
681
686
def __pos__ (self ) -> Self :
682
687
return type (self )(self ._pa_array )
@@ -731,8 +736,19 @@ def _cmp_method(self, other, op):
731
736
)
732
737
return ArrowExtensionArray (result )
733
738
734
- def _evaluate_op_method (self , other , op , arrow_funcs ):
739
+ def _op_method_error_message (self , other , op ) -> str :
740
+ if hasattr (other , "dtype" ):
741
+ other_type = f"dtype '{ other .dtype } '"
742
+ else :
743
+ other_type = f"object of type { type (other )} "
744
+ return (
745
+ f"operation '{ op .__name__ } ' not supported for "
746
+ f"dtype '{ self .dtype } ' with { other_type } "
747
+ )
748
+
749
+ def _evaluate_op_method (self , other , op , arrow_funcs ) -> Self :
735
750
pa_type = self ._pa_array .type
751
+ other_original = other
736
752
other = self ._box_pa (other )
737
753
738
754
if (
@@ -742,10 +758,15 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
742
758
):
743
759
if op in [operator .add , roperator .radd ]:
744
760
sep = pa .scalar ("" , type = pa_type )
745
- if op is operator .add :
746
- result = pc .binary_join_element_wise (self ._pa_array , other , sep )
747
- elif op is roperator .radd :
748
- result = pc .binary_join_element_wise (other , self ._pa_array , sep )
761
+ try :
762
+ if op is operator .add :
763
+ result = pc .binary_join_element_wise (self ._pa_array , other , sep )
764
+ elif op is roperator .radd :
765
+ result = pc .binary_join_element_wise (other , self ._pa_array , sep )
766
+ except pa .ArrowNotImplementedError as err :
767
+ raise TypeError (
768
+ self ._op_method_error_message (other_original , op )
769
+ ) from err
749
770
return type (self )(result )
750
771
elif op in [operator .mul , roperator .rmul ]:
751
772
binary = self ._pa_array
@@ -777,9 +798,14 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
777
798
778
799
pc_func = arrow_funcs [op .__name__ ]
779
800
if pc_func is NotImplemented :
801
+ if pa .types .is_string (pa_type ) or pa .types .is_large_string (pa_type ):
802
+ raise TypeError (self ._op_method_error_message (other_original , op ))
780
803
raise NotImplementedError (f"{ op .__name__ } not implemented." )
781
804
782
- result = pc_func (self ._pa_array , other )
805
+ try :
806
+ result = pc_func (self ._pa_array , other )
807
+ except pa .ArrowNotImplementedError as err :
808
+ raise TypeError (self ._op_method_error_message (other_original , op )) from err
783
809
return type (self )(result )
784
810
785
811
def _logical_method (self , other , op ):
0 commit comments