Skip to content

BUG: inconsistent Series/DataFrame behavior in bitwise ops #52538

Closed
@jbrockmendel

Description

@jbrockmendel
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions