Skip to content

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

@iamlemec

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DataFrameDataFrame data structureIndexingRelated to indexing on series/frames, not to indexes themselvesWarningsWarnings that appear or should be added to pandas

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @iamlemec@jreback@jbrockmendel@arw2019

      Issue actions

        BUG: surprising non-error when assigning a multi-column DataFrame to a single column · Issue #38604 · pandas-dev/pandas