Skip to content

AssertionError from Series.append(DataFrame) with 1.0.0rc0 #30975

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
TomAugspurger opened this issue Jan 13, 2020 · 1 comment · Fixed by #31036
Closed

AssertionError from Series.append(DataFrame) with 1.0.0rc0 #30975

TomAugspurger opened this issue Jan 13, 2020 · 1 comment · Fixed by #31036
Labels
Error Reporting Incorrect or improved errors from pandas good first issue Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@TomAugspurger
Copy link
Contributor

Code Sample, a copy-pastable example if possible

The behavior of the following changed with 1.0.0rc0

>>> import pandas as pd
>>> df = pd.DataFrame({"A": [1,2], "B": [3, 4]})
>>> df.A.append(df)

On 0.25.3, we have

     0    A    B
0  1.0  NaN  NaN
1  2.0  NaN  NaN
0  NaN  1.0  3.0
1  NaN  2.0  4.0

On 1.0.0rc0, we have

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-9-fde662a5b7c4> in <module>
----> 1 df.A.append(df)

~/sandbox/pandas/pandas/core/series.py in append(self, to_append, ignore_index, verify_integrity)
   2541         return self._ensure_type(
   2542             concat(
-> 2543                 to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity
   2544             )
   2545         )

~/sandbox/pandas/pandas/core/base.py in _ensure_type(self, obj)
     93         Used by type checkers.
     94         """
---> 95         assert isinstance(obj, type(self)), type(obj)
     96         return obj
     97

AssertionError: <class 'pandas.core.frame.DataFrame'>

Problem description

I don't think the behavior of 0.25.3 is necessarily correct. I would expect either a TypeError from passing a DataFrame to Series.append, or something like

In [17]: r
Out[17]:
   A    B
0  1  3.0
1  2  4.0
0  1  NaN
1  2  NaN

where the name of the Series is aligned with the DataFrame. We clearly document that the elements passed to append should be Series, so IMO we should raise.

TomAugspurger added a commit to TomAugspurger/dask that referenced this issue Jan 13, 2020
It's unclear what the expected behavior of Series.append(DataFrame)
is. Removing these assertions for now.

xref pandas-dev/pandas#30975
@TomAugspurger TomAugspurger added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jan 13, 2020
TomAugspurger added a commit to dask/dask that referenced this issue Jan 13, 2020
It's unclear what the expected behavior of Series.append(DataFrame)
is. Removing these assertions for now.

xref pandas-dev/pandas#30975
@simonjayhawkins
Copy link
Member

We clearly document that the elements passed to append should be Series, so IMO we should raise.

I agree. I think for this issue, we should restrict to improving the error message to something like TypeError: to_append should be a Series or list/tuple of Series, got <type> since the docs state:

to_appendSeries or list/tuple of Series
   Series to append with self.

and a note in the whatsnew that this now raises

an enhancement to accept a DataFrame could be raised as a separate issue and could be discussed there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas good first issue Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants