Skip to content

raise more specific error if dict is appended to frame wit… #30882

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 3 commits into from
Jan 20, 2020

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Jan 10, 2020

…hout ignore_index

@MarcoGorelli MarcoGorelli changed the title 🥅 raise more specific error if dict is appended to frame wit… raise more specific error if dict is appended to frame wit… Jan 10, 2020
@simonjayhawkins simonjayhawkins added the Error Reporting Incorrect or improved errors from pandas label Jan 10, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Jan 10, 2020
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.

Thanks @MarcoGorelli for the PR. lgtm. although I think that a note in the other section of the whatsnew to say the message has been changed might be warranted. see what others think.

@@ -1170,6 +1170,8 @@ Other
- Bug where :meth:`DataFrame.itertuples` would incorrectly determine whether or not namedtuples could be used for dataframes of 255 columns (:issue:`28282`)
- Handle nested NumPy ``object`` arrays in :func:`testing.assert_series_equal` for ExtensionArray implementations (:issue:`30841`)
- Bug in :class:`Index` constructor incorrectly allowing 2-dimensional input arrays (:issue:`13601`, :issue:`27125`)
- Appending a dictionary to a :class:`DataFrame` without passing ``ignore_index=True`` will raise ``TypeError: Can only append a dict if ignore_index=True``
instead of ``TypeError: Can only append a Series if ignore_index=True or if the Series has a name`` (:issue`30871`)
Copy link
Member

Choose a reason for hiding this comment

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

This will need to go in doc/source/whatsnew/v1.1.0.rst once #30907 is merged

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

The 1.1 file should be available now to move whatsnew

@@ -7023,6 +7023,8 @@ def append(
"""
if isinstance(other, (Series, dict)):
if isinstance(other, dict):
if not ignore_index:
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding another branch here can you just use an f-string and do f"Can only append a {type(other)}...

Copy link
Member Author

Choose a reason for hiding this comment

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

Could do, but then I'll need to add another branch later as the message for Series has an extra part compared to that for dict: "or if the Series has a name"

@WillAyd WillAyd merged commit 15bacea into pandas-dev:master Jan 20, 2020
@WillAyd
Copy link
Member

WillAyd commented Jan 20, 2020

Thanks @MarcoGorelli

@MarcoGorelli MarcoGorelli deleted the append-dict branch January 20, 2020 22:28
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message for DataFrame.append(<dict-like>)
3 participants