@@ -681,7 +681,12 @@ def __invert__(self) -> Self:
681681 return type (self )(pc .invert (self ._pa_array ))
682682
683683 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
685690
686691 def __pos__ (self ) -> Self :
687692 return type (self )(self ._pa_array )
@@ -736,8 +741,19 @@ def _cmp_method(self, other, op) -> ArrowExtensionArray:
736741 )
737742 return ArrowExtensionArray (result )
738743
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+
739754 def _evaluate_op_method (self , other , op , arrow_funcs ) -> Self :
740755 pa_type = self ._pa_array .type
756+ other_original = other
741757 other = self ._box_pa (other )
742758
743759 if (
@@ -747,10 +763,15 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
747763 ):
748764 if op in [operator .add , roperator .radd ]:
749765 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
754775 return type (self )(result )
755776 elif op in [operator .mul , roperator .rmul ]:
756777 binary = self ._pa_array
@@ -782,9 +803,14 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
782803
783804 pc_func = arrow_funcs [op .__name__ ]
784805 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 ))
785808 raise NotImplementedError (f"{ op .__name__ } not implemented." )
786809
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
788814 return type (self )(result )
789815
790816 def _logical_method (self , other , op ) -> Self :
0 commit comments