Skip to content

BUG: DafaFrame.insert doesn't raise an exception when inserting another DataFrame #42403

Closed
@YarShev

Description

@YarShev
  • 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.


Code Sample, a copy-pastable example

import pandas
df = pandas.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
df.insert(1, "newcol", df)
df
   col1 newcol  col2
0     1   col1     3
1     2   col2     4

Problem description

Dataframe should take int, Series, or array-like as a value and throw an exception in case DataFrame is passed.

Expected Output

Behavior in 1.2.5

import pandas
df = pandas.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
df.insert(1, "newcol", df)
ValueError: Wrong number of items passed 2, placement implies 1

Output of pd.show_versions()

pandas : 1.3.0
numpy : 1.20.3
pytz : 2020.1
dateutil : 2.8.1
pip : 21.1.2
setuptools : 49.6.0.post20210108
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : 4.0.2
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.24.1
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 2021.05.0
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.7
pandas_gbq : 0.15.0
pyarrow : 3.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : 1.4.18
tables : 3.6.1
tabulate : None
xarray : 0.18.2
xlrd : 2.0.1
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesTestingpandas testing functions or related to the test suitegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions