-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fix df.where(cond) when cond is empty #21947
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
BUG: fix df.where(cond) when cond is empty #21947
Conversation
@pajachiet : Thanks for the PR! Can you add a test and a From a higher level, this seems like a corner case to me here: why would you want to pass in an empty object for |
how is this not an error? if you don’t have a conf then where doesn’t make sure |
@jreback : That's what I was wondering too myself. Perhaps a better error message is in order? |
Codecov Report
@@ Coverage Diff @@
## master #21947 +/- ##
==========================================
+ Coverage 92.25% 92.25% +<.01%
==========================================
Files 161 161
Lines 51169 51170 +1
==========================================
+ Hits 47207 47208 +1
Misses 3962 3962
Continue to review full report at Codecov.
|
Hello I wanted to write a test, but I did not find where were the unit tests for the 'where' function. This is indeed a corner case, when both df and cond are empty. Example:
This kind of corner case do happen :
I had the same kind of corner case with df.duplicated in previous version of pandas. |
yeah certainly could have a better error message (e.g. you can detect the .empty), but this should just be an error. |
the |
Yes, But it is a bug to raise an error when they are both empty, no ? As the bug is on One could also explicitly check for
|
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.
needs a test
add in pandas/tests/frame/test_indexing (you may need one for series, though I don't know if this path is hit, in pandas/tests/series/tests_indexing)
Hello @pajachiet! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 09, 2018 at 11:45 Hours UTC |
8f799db
to
6772d0e
Compare
d04e677
to
319f1e2
Compare
Hello, |
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.
pls add a whatsnew entry in v0.24.0 / bug fixes / reshaping
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.
use this PR number as the issue number (as I don't think there is an issue about this)
closing as stale. if you'd like to continue, pls ping. |
I believe the bug in the CI was not caused by changes in this PR. This PR fixed a simple but real bug. I managed to fix it in another way for my client, so I only did this PR if it can improve pandas, especially in those edges cases that can be really annoying. I added a test, a whatsnew entry and answered your comments. Otherwise keep it close, it's too much an investment for such a minor improvment. |
@pajachiet : Do you want to finish this up? I think it requires a rebase, that's all. |
well if it’s a bug then it will probably come up again it’s always helpful to improve things |
Let's take this for another spin. |
When `cond` is empty, `cond.dtypes` are objects, which raises a `ValueError`. Now, it does not. Original author: @pajachiet
92ccd06
to
3342c09
Compare
@jreback : Is there a reason why we can't attempt to merge this for |
Just saw your email regarding |
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 comment.
thanks! |
Many thanks ! :) |
ValueError: Boolean array expected for the condition, not object
git diff upstream/master -u -- "*.py" | flake8 --diff