BUG: inconsistent Series/DataFrame behavior in bitwise ops · Issue #52538 · pandas-dev/pandas (original) (raw)
ser = pd.Series([1, 2], index=['a', 'b']) ser2 = pd.Series([3, 4], index=['b', 'c']) df = ser.to_frame() df2 = ser2.to_frame()
ser & ser2 a False b True c False
df & df2 Traceback (most recent call last): [...] TypeError: unsupported operand type(s) for &: 'float' and 'bool'
Series._logical_method passes align_asobject=True
to _align_for_op
, which DataFrame does not.
The net effect of this is in some ways analogous to DataFrame._arith_method doing _arith_method_with_reindex to only operate on the intersection of columns and then reindexing the result. Maybe we could do something similar on the Series method instead of casting.
Regardless, the behaviors should match.