Skip to content

Commit b301ac0

Browse files
committed
BUG (string dtype): comparison of string column to mixed object column fails pandas-dev#60228
1 parent 56bc8b1 commit b301ac0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,14 +726,21 @@ def _cmp_method(self, other, op) -> ArrowExtensionArray:
726726
other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)
727727
) or isinstance(getattr(other, "dtype", None), CategoricalDtype):
728728
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()
732732
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())
734738
result = pc_func(self_array, other_array)
735739
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)
737744
except pa.ArrowNotImplementedError:
738745
# TODO: could this be wrong if other is object dtype?
739746
# in which case we need to operate pointwise?

0 commit comments

Comments
 (0)