-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add example usage to DataFrame.filter #12399
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
Note that this routine does not filter a dataframe on its | ||
contents. The filter is applied to the labels of the index. | ||
This method is a thin veneer on top of :ref:`DateFrame Select | ||
<DataFrame.select>` |
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 last sentence is not necessary.
Removed the "thin veneer" comment and added a See Also referring to |
can you update |
Sorry for being a newbie, but update in what way? Do you want me to rebase my |
you need to rebase on master first |
I updated my branch, but 24hrs later the CI builds are still not complete. Is that unusual or expected? Also the CI build for python 3.5 failed but I don't see how it has anything to do with changes I created. |
Travis was having some issues ok now ithe 3.5 build on. numpy master is currently failing but that is ok |
can you rebase / update according to comments |
can you rebase / update |
can you update |
Current coverage is 83.76%@@ master #12399 diff @@
========================================
Files 138 135 -3
Lines 50721 49640 -1081
Methods 0 0
Branches 0 0
========================================
- Hits 42723 41583 -1140
- Misses 7998 8057 +59
Partials 0 0
|
As requested, added test for mutually exclusive arguments in DataFrame.filter and added unit tests for same. |
""" | ||
import re | ||
|
||
args = locals().copy() | ||
nkw = sum(map(lambda x: operator.getitem(args,x)!=None, ['items', 'like', 'regex'])) |
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 seems a bit complicated for what we want to achieve (the locals is certainly not needed I think).
Using a similar construct: sum(map(lambda x: x is not None, [item, like, regex]))
(but using a list comprehension is maybe easier to read: sum([x is not None for x in [item, like, regex]])
)
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, changing to,
nkw = sum([operator.getitem(args,x) is not None for x in ['items', 'like', 'regex']])
if nkw > 1:
raise TypeError("filter(): keyword arguments are mutually exclusive")
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.
opps, I didn't understand...now using,
nkw = sum([x is not None for x in [items, like, regex]])
Enforcing mutually exclusive arguments in frame.filter() is an incompatible change that is going to break some code, somewhere. Should this be called out in the release notes? I would like to make a case that this API should be deprecated at this time. It adds little value over reindex and select at the expense of an API that is different than just about anything else. |
if nkw > 1: | ||
raise TypeError('Keyword arguments `items`, `like`, or `regex` ' | ||
'are mutually exclusive') | ||
|
||
if axis is None: | ||
axis = self._info_axis_name | ||
axis_name = self._get_axis_name(axis) |
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.
e.g. checked here
@cswarth yes pls add a whatsnew note about the mutually exclusive args. |
already slated to deprecate in 0.19.0: #12401 |
- add sample usage - enforce mutual exlusion of keyword arguments - add note to what's new doc calling out API change
thanks @cswarth |
Updates doc comments for
DataFrame.filter
and adds usage examples.Fixed errors identified by
flake8
and correctly rebase my branch before issuing PR.DataFrame.
filter
(items=None, like=None, regex=None, axis=None)¶Subset rows or columns of dataframe according to labels in the index.
Note that this routine does not filter a dataframe on its contents. The filter is applied to the labels of the index. This method is a thin veneer on top of DateFrame Select
items : list-like
like : string
regex : string (regular expression)
axis : int or None
same type as input object with filtered info axis
Notes
The
items
,like
, andregex
parameters should be mutually exclusive, but this is not checked.axis
defaults to the info axis that is used when indexing with[]
.Examples