Skip to content

BUG: Appending empty list to DataFrame #28769 #28834

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

Merged
merged 10 commits into from
Nov 16, 2019
Merged

BUG: Appending empty list to DataFrame #28769 #28834

merged 10 commits into from
Nov 16, 2019

Conversation

asishm
Copy link
Contributor

@asishm asishm commented Oct 8, 2019

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asishm

from the docs..

other : DataFrame or Series/dict-like object, or list of these
The data to append.

shouldn't passing an empty list raise an Exception. but perhaps with a more user friendly message.

@asishm
Copy link
Contributor Author

asishm commented Oct 11, 2019

@simonjayhawkins
That sounds reasonable. The reason for implementing it to return the same dataframe was based on the suggestion in #28769. I could update the docs to mention that if other is an empty list, then it would return the same dataframe. Or maybe explicitly state that passing an empty list would result in an Exception (ValueError?)

@simonjayhawkins
Copy link
Member

I'm not sure. see what others think.

not raising on an empty list is perhaps more pythonic, but without checking, I'm not sure how we handle this scenario in other methods.

It maybe worth adding type annotations to append and see what mypy has to offer.

@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
@@ -129,6 +129,17 @@ def test_concat_tuple_keys(self):
)
assert_frame_equal(results, expected)

def test_append_empty_list(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you parameterize with empty list, tuple, np.ndarray

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback Please see the reply in the other comment (#28834 (comment))

@pep8speaks
Copy link

pep8speaks commented Oct 28, 2019

Hello @asishm! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-11-16 20:08:13 UTC

@jreback
Copy link
Contributor

jreback commented Nov 13, 2019

can you merge master

@asishm
Copy link
Contributor Author

asishm commented Nov 15, 2019

Rebased master. I'm not sure if there's an issue with the CI or if I messed something up

@asishm
Copy link
Contributor Author

asishm commented Nov 15, 2019

Rebased master. I'm not sure if there's an issue with the CI or if I messed something up

I see this in the Travis logs
https://travis-ci.org/pandas-dev/pandas/jobs/612167009#L2418

psql: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
The command "ci/setup_env.sh" failed and exited with 2 during .

@jreback jreback merged commit e639af2 into pandas-dev:master Nov 16, 2019
@jreback
Copy link
Contributor

jreback commented Nov 16, 2019

thanks @asishm

@asishm asishm deleted the append_empty_bugfix branch November 17, 2019 01:01
Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
@joaoe
Copy link

joaoe commented Nov 18, 2019

@asishm

shouldn't passing an empty list raise an Exception. but perhaps with a more user friendly message.

That would be quite special behavior:

123 + 0 == 123
x = []; x.extend([]); x == []
"a" + "" == "a"

empty lists, strings, etc should be neutral in operations instead of causing errors. That saves an unecessary if check for a corner case.

@asishm asishm restored the append_empty_bugfix branch November 19, 2019 15:48
@asishm asishm deleted the append_empty_bugfix branch November 19, 2019 15:53
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 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
Development

Successfully merging this pull request may close these issues.

DataFrame.append with empty list raises IndexError
5 participants