Open
Description
Currently, for the plain bool
dtype we explicitly check for some operations and raise an error, while those actually work in numpy. For example:
>>> arr = np.array([True, False, True])
>>> arr / True
array([1., 0., 1.])
>>> pd.Series(arr) / True
...
NotImplementedError: operator '/' not implemented for bool dtypes
This is done for the division and power operations (not_allowed={"/", "//", "**"}
):
pandas/pandas/core/computation/expressions.py
Lines 215 to 218 in 934cad6
For the nullable BooleanArray, for now we simply relied on the operations as defined by the underlying numpy bool array:
>>> pd.array(arr) / True
<FloatingArray>
[1.0, 0.0, 1.0]
Length: 3, dtype: Float64
That's for the BooleanArray
, but the check is currently done on the "array_op" level (but because it is done within expressions.py, we don't run that check for EAs, xref #41161).
So questions:
- Do we actually want to continue disallowing this operation, while numpy allows it? (also, eg
pd.Series(arr) / 1
does work, it's only disallowed if both operands are boolean) - If we keep disallowing it, we should probably also disallow it on the
BooleanArray
level, and not only check it on the DataFrame/Series ops level inarray_ops.py
?