Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jbrockmendel opened this issue Apr 8, 2023 · 0 comments · Fixed by #52839
Closed

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

jbrockmendel opened this issue Apr 8, 2023 · 0 comments · Fixed by #52839
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Apr 8, 2023

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.

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member Numeric Operations Arithmetic, Comparison, and Logical operations and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant