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

Pandas vs Numpy broadcasting discrepancy #22686

Closed
timlod opened this issue Sep 13, 2018 · 0 comments · Fixed by #23000
Closed

Pandas vs Numpy broadcasting discrepancy #22686

timlod opened this issue Sep 13, 2018 · 0 comments · Fixed by #23000
Labels
Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@timlod
Copy link
Contributor

timlod commented Sep 13, 2018

Code Sample, a copy-pastable example if possible

# Not working in full pandas
pd.DataFrame(np.full((5,5), True)) & np.full((1,5), False)
#ValueError: Unable to coerce to DataFrame, shape must be (5, 5): given (1, 5)

# After extracting the numpy array it works as expected:
pd.DataFrame(np.full((5,5), True)).values & np.full((1,5), False)

Problem description

I have a dataframe with shape (m,n), each column filled with bools.
Now I have a numpy (column) vector of length n filled with bools and I would like to apply the logical AND (&) such that the operation is broadcast from the vector onto each column.
This works only when using df.values, not when applying & on the dataframe.

The same holds for other operations such as *, /
I am not sure whether this is intended behaviour - I could not find the matching documentation.

@jreback jreback added the Numeric Operations Arithmetic, Comparison, and Logical operations label Oct 6, 2018
@jreback jreback added this to the 0.24.0 milestone Oct 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants