-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Conversation
There was a problem hiding this 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.
c82b88d
to
2dc4b3e
Compare
doc/source/whatsnew/v1.0.0.rst
Outdated
@@ -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`) |
There was a problem hiding this comment.
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
There was a problem hiding this 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: |
There was a problem hiding this comment.
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)}...
There was a problem hiding this comment.
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"
2dc4b3e
to
3dac8b8
Compare
00852df
to
891bfe5
Compare
Thanks @MarcoGorelli |
…hout ignore_index
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff