Skip to content

BUG: surprising non-error when assigning a multi-column DataFrame to a single column #38604

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

Closed
3 tasks done
iamlemec opened this issue Dec 21, 2020 · 0 comments · Fixed by #39341
Closed
3 tasks done
Labels
DataFrame DataFrame data structure Indexing Related to indexing on series/frames, not to indexes themselves Warnings Warnings that appear or should be added to pandas
Milestone

Comments

@iamlemec
Copy link
Contributor

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Assigning a multi-column DataFrame to a single column does not raise an error and simply assigns the first column of the DataFrame to the column. Below is an example:

df1 = pd.DataFrame({'a': [0, 1, 2, 3], 'b': [4, 5, 6, 7]}) 
df2 = pd.DataFrame({'c': [8, 9, 10, 11], 'd': [12, 13, 14, 15]}) 
df1['b'] = df2

This seems like one of the instances where not raising an error might ease some short-term pain but could mask underlying issues with a user's code. This behavior seems to have been around for a while. It occurs in master and as far back as 1.0.3.

@iamlemec iamlemec added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 21, 2020
@arw2019 arw2019 added Copy / view semantics Warnings Warnings that appear or should be added to pandas DataFrame DataFrame data structure and removed Needs Triage Issue that has not been reviewed by a pandas team member Bug labels Dec 22, 2020
@jbrockmendel jbrockmendel added Indexing Related to indexing on series/frames, not to indexes themselves and removed Copy / view semantics labels Dec 30, 2020
@jreback jreback added this to the 1.3 milestone Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataFrame DataFrame data structure Indexing Related to indexing on series/frames, not to indexes themselves Warnings Warnings that appear or should be added to pandas
Projects
None yet
4 participants