Open cyrusmaher opened 6 years ago
In a similar vein:
>>> df = pd.DataFrame({'likes_hockey' : [True, True, False],
... 'likes_soccer' : [True, False, False]})
>>> df.likes_hockey & df.likes_soccer # works for series
0 True
1 False
2 False
dtype: bool
>>> # df.bitwise_and(df.likes_soccer, axis='rows') # desirable, but not implemented
>>> df.mul(df.likes_soccer, axis='rows') # implemented, but complains and recommends '&'
/Users/mfenner/anaconda3/lib/python3.7/site-packages/pandas/core/computation/expressions.py:178:
UserWarning: evaluating in Python space because the '*' operator is not supported by numexpr for the
bool dtype, use '&' instead
f"evaluating in Python space because the {repr(op_str)} "
likes_hockey likes_soccer
0 True True
1 False False
2 False False
>>> # but neither of these broadcast/align appropriately (which is expected):
>>> # df & df.likes_soccer # fails
>>> # df.likes_soccer & df # fails
Much of this might apply to np.logical_and
as well (and the other bitwise_
and logical_
operators/functions).
Code Sample
Problem description
Bitwise operations between floats and bools error out in numpy. They error out in pandas too if the first argument is a
float
, but not if the first argument is abool
.Expected Output
ufunc 'bitwise_and' not supported for the input types
Output of
pd.show_versions()