Skip to content

Series.append(DataFrame) should throw TypeError #31413

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
hvardhan20 opened this issue Jan 29, 2020 · 2 comments · Fixed by #32090
Closed

Series.append(DataFrame) should throw TypeError #31413

hvardhan20 opened this issue Jan 29, 2020 · 2 comments · Fixed by #32090
Labels
API Design Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@hvardhan20
Copy link
Contributor

hvardhan20 commented Jan 29, 2020

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> pd.__version__
'1.0.0rc0+233.gec0996c67'
>>> df = pd.DataFrame({'A':[1,2]})
>>> df.A.append(df)
     0    A
0  1.0  NaN
1  2.0  NaN
0  NaN  1.0
1  NaN  2.0

Problem description

The behavior of append is the same as it is in 0.25.3 when a DataFrame is appended to Series. But it should actually throw a TypeError when passed a DataFrame.
We clearly document that the elements passed to append should be Series or list/tuple of Series.
Also according to this, a TypeError seems appropriate. The change can be implemented for 1.0.1 or 1.1 after this discussion.

Expected Output

>>> df = pd.DataFrame({'A':[1, 2]})
>>> df.A.append([df])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Work\Git projects\pandas\pandas\core\series.py", line 2572, in append
    raise TypeError(msg)
TypeError: to_append should be a Series or list/tuple of Series, got DataFrame

Output of pd.show_versions()

INSTALLED VERSIONS

commit : ec0996c
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.0rc0+233.gec0996c67.dirty
numpy : 1.17.0
pytz : 2018.9
dateutil : 2.8.0
pip : 19.3.1
setuptools : 44.0.0.post20200106
Cython : 0.29.14
pytest : 4.3.1
hypothesis : 5.1.5
sphinx : 1.8.5
blosc : None
feather : 0.4.0
xlsxwriter : 1.1.5
lxml.etree : 4.3.2
html5lib : 1.0.1
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.10
IPython : 7.4.0
pandas_datareader: None
bs4 : 4.6.3
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.3.2
matplotlib : 3.0.3
numexpr : 2.6.9
odfpy : None
openpyxl : 2.6.1
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pytest : 4.3.1
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.1
tables : 3.5.1
tabulate : 0.8.6
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.5
numba : 0.43.1

@simonjayhawkins simonjayhawkins added API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jan 29, 2020
@MarcoGorelli
Copy link
Member

Thanks @hvardhan20 - are you interested in submitting a pull request?

@MarcoGorelli MarcoGorelli added the Error Reporting Incorrect or improved errors from pandas label Feb 13, 2020
@hvardhan20
Copy link
Contributor Author

Yes @MarcoGorelli

@jreback jreback added this to the 1.1 milestone Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants