@@ -676,7 +676,12 @@ def __invert__(self) -> Self:
676676 return type (self )(pc .invert (self ._pa_array ))
677677
678678 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
680685
681686 def __pos__ (self ) -> Self :
682687 return type (self )(self ._pa_array )
@@ -731,8 +736,19 @@ def _cmp_method(self, other, op):
731736 )
732737 return ArrowExtensionArray (result )
733738
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 :
735750 pa_type = self ._pa_array .type
751+ other_original = other
736752 other = self ._box_pa (other )
737753
738754 if (
@@ -742,10 +758,15 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
742758 ):
743759 if op in [operator .add , roperator .radd ]:
744760 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
749770 return type (self )(result )
750771 elif op in [operator .mul , roperator .rmul ]:
751772 binary = self ._pa_array
@@ -777,9 +798,14 @@ def _evaluate_op_method(self, other, op, arrow_funcs):
777798
778799 pc_func = arrow_funcs [op .__name__ ]
779800 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 ))
780803 raise NotImplementedError (f"{ op .__name__ } not implemented." )
781804
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
783809 return type (self )(result )
784810
785811 def _logical_method (self , other , op ):
0 commit comments