-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: harmonize drop/reindex/rename args (GH12392) - drop #17644
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
API: harmonize drop/reindex/rename args (GH12392) - drop #17644
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.
lgtm some minor doc comments
prob should update usage in the main docs
@@ -89,6 +89,24 @@ This does not raise any obvious exceptions, but also does not create a new colum | |||
|
|||
Setting a list-like data structure into a new attribute now raise a ``UserWarning`` about the potential for unexpected behavior. See :ref:`Attribute Access <indexing.attribute_access>`. | |||
|
|||
``drop`` now also accepts index/columns keywords |
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.
add ref here
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 is only needed when you actually want to explicitly link to it from somewhere else in the docs, so I personally prefer to only add it when actually needed
(bug can certainly add it for consistency)
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.
no, all sub-sections should have a reference as a general rule. yes we may not always link to it, but by definition when creating a non-trivial sub-section it should have a reference
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.
There is nothing "by definition" about it (I mean, sphinx does not require it). IMO it just gives more overhead by always asking contributors to do this.
pandas/core/generic.py
Outdated
return obj | ||
|
||
def _drop_axis(self, labels, axis, level=None, errors='raise'): | ||
|
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.
add doc string here
res1 = df.drop(['a'], axis=0).drop(['d'], axis=1) | ||
res2 = df.drop(index=['a'], columns=['d']) | ||
tm.assert_frame_equal(res1, res2) | ||
|
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.
test with columns as well
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.
Did you mean for the error test? (added one for that) Or for one of the tests above?
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.
yep
axis : int or axis name | ||
Whether to drop labels from the index (0 / 'index') or | ||
columns (1 / 'columns'). | ||
index, columns : single label or list-like |
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.
Perhaps add a Notes
section saying that specifying both labels
and index
or columns
will raise an error.
Codecov Report
@@ Coverage Diff @@
## master #17644 +/- ##
==========================================
- Coverage 91.22% 91.2% -0.02%
==========================================
Files 163 163
Lines 49655 49669 +14
==========================================
+ Hits 45297 45301 +4
- Misses 4358 4368 +10
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17644 +/- ##
==========================================
- Coverage 91.22% 91.2% -0.02%
==========================================
Files 163 163
Lines 49655 49669 +14
==========================================
+ Hits 45297 45301 +4
- Misses 4358 4368 +10
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17644 +/- ##
==========================================
- Coverage 91.26% 91.24% -0.02%
==========================================
Files 163 163
Lines 49776 49790 +14
==========================================
+ Hits 45426 45431 +5
- Misses 4350 4359 +9
Continue to review full report at Codecov.
|
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.
minor comments. merge on green.
columns (1 / 'columns'). | ||
index, columns : single label or list-like | ||
Alternative to specifying `axis` (``labels, axis=1`` is | ||
equivalent to ``columns=labels``). |
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.
add a versionadded tag
res1 = df.drop(['a'], axis=0).drop(['d'], axis=1) | ||
res2 = df.drop(index=['a'], columns=['d']) | ||
tm.assert_frame_equal(res1, res2) | ||
|
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.
yep
Thanks Joris! |
…17644) * API: harmonize drop/reindex/rename args (GH12392) - drop * fixups * add versionadded
…17644) * API: harmonize drop/reindex/rename args (GH12392) - drop * fixups * add versionadded
xref #12392.
For now this only deals with
drop
(making it similar withreindex
), and not the other way around (reindex
similar todrop
). So the title is not fully correct, but this is the more easy part.