Skip to content

DataFrame.append with empty list raises IndexError #28769

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
joaoe opened this issue Oct 3, 2019 · 3 comments · Fixed by #28834
Closed

DataFrame.append with empty list raises IndexError #28769

joaoe opened this issue Oct 3, 2019 · 3 comments · Fixed by #28834
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@joaoe
Copy link

joaoe commented Oct 3, 2019

Code Sample

>>> import pandas
>>> pandas.DataFrame().append([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".env\lib\site-packages\pandas\core\frame.py", line 7108, in append
    elif isinstance(other, list) and not isinstance(other[0], DataFrame):
IndexError: list index out of range
>>> pandas.__version__
'0.25.1'

Problem description

Crash when passing empty sequence to DataFrame.append

Expected Output

No crash.
The source DataFrame is returned intact.

Version

Version 0.25.1. Happens in master.
Problem line
https://github.com/pandas-dev/pandas/blob/master/pandas/core/frame.py#L7014

@jbrockmendel
Copy link
Member

What output are you hoping to see here? Still an empty DataFrame?

@joaoe
Copy link
Author

joaoe commented Oct 3, 2019

I guess the source DataFrame() is expected since an empty sequence is just empty and there is nothing to append.

Like this

pandas.DataFrame({"a":[1,2]}).append([pandas.DataFrame()])

@joaoe joaoe changed the title Crash in Crash in pandas.DataFrame.append Oct 5, 2019
@jbrockmendel
Copy link
Member

Seems reasonable. A PR would be welcome.

@jreback jreback added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Oct 11, 2019
@jreback jreback added this to the 1.0 milestone Oct 11, 2019
@simonjayhawkins simonjayhawkins changed the title Crash in pandas.DataFrame.append DataFrame.append with empty list raises IndexError Oct 13, 2019
Reksbril pushed a commit to Reksbril/pandas that referenced this issue Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
3 participants