Skip to content

BUG (string dtype): logical operation with bool and string failing #60234

Open
@jorisvandenbossche

Description

@jorisvandenbossche

We do allow using logical operators like | to be used with non-boolean data (at which point the non-bool series would be cast to bool, I assume). For example:

>>> ser1 = pd.Series([False, False])
>>> ser2 = pd.Series([0.0, 0.1])
>>> ser1 | ser2
0    False
1     True
dtype: bool

This also worked with strings in object dtype:

>>> ser2 = pd.Series(["", "b"], dtype=object)
>>>  ser1 | ser2
0    False
1     True
dtype: bool

but currently fails with the pyarrow-backed string dtype:

>>> pd.options.future.infer_string = True
>>> ser2 = pd.Series(["", "b"])
>>> ser1 | ser2
...

File ~/scipy/repos/pandas/pandas/core/arrays/arrow/array.py:833, in ArrowExtensionArray._logical_method(self, other, op)
    831     return self._evaluate_op_method(other, op, ARROW_BIT_WISE_FUNCS)
    832 else:
--> 833     return self._evaluate_op_method(other, op, ARROW_LOGICAL_FUNCS)

File ~/scipy/repos/pandas/pandas/core/arrays/arrow/array.py:824, in ArrowExtensionArray._evaluate_op_method(self, other, op, arrow_funcs)
    822     result = pc_func(self._pa_array, other)
    823 except pa.ArrowNotImplementedError as err:
--> 824     raise TypeError(self._op_method_error_message(other_original, op)) from err
    825 return type(self)(result)

TypeError: operation 'ror_' not supported for dtype 'str' with dtype 'bool'

Metadata

Metadata

Assignees

Labels

BugNumeric OperationsArithmetic, Comparison, and Logical operationsStringsString extension data type and string data

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions