ENH: Allow where/mask/Indexers to accept callable#12539
ENH: Allow where/mask/Indexers to accept callable#12539sinhrks wants to merge 1 commit intopandas-dev:masterfrom
Conversation
|
One potential problem is when you subclass |
|
Do you know such a package? The logic is not specific here and I don't think we have to care ATM. |
|
I don't know anyone that uses it that way. But since the order of consideration is relevant, I think it should be documented that the args are first tested for callability. |
|
let's simultaneously do all of the chained reshaping ops #11485 in 0.18.1, making them consistent. |
9b39b6f to
f2430c4
Compare
|
Sure, once done and changed the title. |
doc/source/whatsnew/v0.18.1.txt
Outdated
There was a problem hiding this comment.
need to have some tests if people try to pass something like:
df.loc[lambda x: ...., list_of_columns] which is a bit odd, but I suppose ok, otherwise we need to interpret this
There was a problem hiding this comment.
OK, added some tests for mixture of lamda and scalar/list.
doc/source/whatsnew/v0.18.1.txt
Outdated
There was a problem hiding this comment.
The following methods / indexers now acccept a callable
Current coverage is 83.91%@@ master #12539 diff @@
==========================================
Files 136 136
Lines 49908 49933 +25
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 41876 41901 +25
Misses 8032 8032
Partials 0 0
|
doc/source/whatsnew/v0.18.1.txt
Outdated
There was a problem hiding this comment.
What do you mean by this?
|
ok, how about for |
|
You already get an error when passing a callable to |
|
I would definitely raise if the input to |
|
ok @sinhrks if you can make those mods would be great. (you might need to adjust docs/example as I think you use .query, but can just change to |
7ad04b7 to
ebe5aaf
Compare
|
Thanks for all the feedbacks. Updated. Lmk if I missed something. |
There was a problem hiding this comment.
I would make this a separate file: indexing/test_callables.py
|
just minor change otherwise lgtm. |
doc/source/whatsnew/v0.18.1.txt
Outdated
There was a problem hiding this comment.
I would add this example somewhere in the where docs as well (http://pandas-docs.github.io/pandas-docs-travis/indexing.html#the-where-method-and-masking)
|
@sinhrks Can you also update the docstrings for loc/iloc/ix (eg for loc https://github.com/pydata/pandas/blob/65ed3afd092908130905e7d86ff1b6b9c2002d00/pandas/core/indexing.py#L1314), these are used in the API docs. For the rest, +1! |
pandas/core/frame.py
Outdated
There was a problem hiding this comment.
add a versionadded tag here (and other doc-strings)
There was a problem hiding this comment.
assign impl is unchanged.
|
@sinhrks some very minor doc-changes. ping when pushed. |
|
thanks @sinhrks ! awesome enhancement! |
git diff upstream/master | flake8 --diffCurrent impl is very simple like
assign. Another idea is applying some restriction to return value fromcallable(for example, only allow alignedDataFrameor scalar).