@@ -726,14 +726,21 @@ def _cmp_method(self, other, op) -> ArrowExtensionArray:
726
726
other , (ArrowExtensionArray , np .ndarray , list , BaseMaskedArray )
727
727
) or isinstance (getattr (other , "dtype" , None ), CategoricalDtype ):
728
728
try :
729
- if pa . types . is_string ( self ._pa_array . type ):
730
- other_array = self . _box_pa ( other )
731
- self_array = self . _pa_array . cast ( pa . large_string () )
729
+ other_array = self ._box_pa ( other )
730
+ if isinstance ( other_array . type , pa . DictionaryType ):
731
+ other_array = other_array . dictionary_decode ( )
732
732
if pa .types .is_string (other_array .type ):
733
- other_array = other_array .cast (pa .large_string ())
733
+ other_array = other_array .cast (pa .string ())
734
+ if pa .types .is_string (self ._pa_array .type ):
735
+ self_array = self ._pa_array
736
+ if not pa .types .is_string (other_array .type ):
737
+ other_array = other_array .cast (pa .string ())
734
738
result = pc_func (self_array , other_array )
735
739
else :
736
- result = pc_func (self ._pa_array , self ._box_pa (other ))
740
+ result = pc_func (self ._pa_array , other_array )
741
+ if result .type == pa .string ():
742
+ result = result .cast (self ._pa_array .type )
743
+ return type (self )(result )
737
744
except pa .ArrowNotImplementedError :
738
745
# TODO: could this be wrong if other is object dtype?
739
746
# in which case we need to operate pointwise?
0 commit comments