-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fixed handling of boolean indexing with 2-d ndarrays #18645
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
Looks like just one error. The rest are the same as before the change:
|
Codecov Report
@@ Coverage Diff @@
## master #18645 +/- ##
==========================================
- Coverage 91.57% 91.55% -0.03%
==========================================
Files 150 150
Lines 48933 48937 +4
==========================================
- Hits 44812 44803 -9
- Misses 4121 4134 +13
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.
lgtm. pls add a whatsnew note for 0.22, bug fixes in indexing.
pandas/tests/frame/test_indexing.py
Outdated
expected.values[mask.values] = nan | ||
assert_frame_equal(df, expected) | ||
|
||
# index with DataFrame |
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.
can you make these a separate test (test_setitem_boolean_ndarary)
472a1e2
to
925de27
Compare
Hello @dhirschfeld! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on December 30, 2017 at 14:24 Hours UTC |
925de27
to
7f8f825
Compare
@jreback - test moved to it's own function and whatsnew entry added |
56684d0
to
5ab8581
Compare
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.
small changes, ping on green.
pandas/tests/frame/test_indexing.py
Outdated
@@ -542,6 +541,16 @@ def test_setitem_boolean(self): | |||
np.putmask(expected.values, mask.values, df.values * 2) | |||
assert_frame_equal(df, expected) | |||
|
|||
def test_setitem_boolean_ndarary(self): | |||
df = self.frame.copy() |
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.
can you add the issue number as a comment here, also sp on ndarray
pandas/tests/frame/test_indexing.py
Outdated
mask = df > np.abs(df) | ||
expected = df.copy() | ||
expected.values[mask.values] = nan | ||
# index with 2-d boolean ndarray |
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 blank line before the comment
pandas/tests/frame/test_indexing.py
Outdated
@@ -542,6 +541,16 @@ def test_setitem_boolean(self): | |||
np.putmask(expected.values, mask.values, df.values * 2) | |||
assert_frame_equal(df, expected) | |||
|
|||
def test_setitem_boolean_ndarary(self): |
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.
can you parametrize to pass both lambda mask: mask, lambda mask: mask.value
(IOW pass a dataframe and the ndarray)
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.
can you do this, IOW, use parametrize
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.
You saw my comment? You definitely want to use parametrize rather than just adding it like I did below?
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.
yes
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.
can you parametrize this
pandas/tests/frame/test_indexing.py
Outdated
# index with boolean DataFrame | ||
actual = df.copy() | ||
actual[mask] = nan | ||
assert_frame_equal(actual, expected) |
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.
I just added this block to the test rather than try and use pytest parameterisation as it seem a more straightforward and direct way to do it. Possibly just my lack of familiarity with pytest fixtures but I think they might be overkill for this usecase.
Just thinking about this - as a bug fix wouldn't it be more appropriate for 0.21.1? |
yes its a bug fix, but it is substantially different, so put in 0.22. folks may be relying on this behavior (event though its wrong). |
Fair enough. I think it's good to go then if there are no more changes you'd like? |
pandas/tests/frame/test_indexing.py
Outdated
@@ -542,6 +541,16 @@ def test_setitem_boolean(self): | |||
np.putmask(expected.values, mask.values, df.values * 2) | |||
assert_frame_equal(df, expected) | |||
|
|||
def test_setitem_boolean_ndarary(self): |
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.
can you do this, IOW, use parametrize
pls rebase & ping on green (the 3.6 build is failing unrelated so that may fail the build), but otherwise. |
doc/source/whatsnew/v0.22.0.txt
Outdated
@@ -268,6 +268,7 @@ Indexing | |||
- Bug in :func:`IntervalIndex.symmetric_difference` where the symmetric difference with a non-``IntervalIndex`` did not raise (:issue:`18475`) | |||
- Bug in indexing a datetimelike ``Index`` that raised ``ValueError`` instead of ``IndexError`` (:issue:`18386`). | |||
- Bug in tz-aware :class:`DatetimeIndex` where addition/subtraction with a :class:`TimedeltaIndex` or array with ``dtype='timedelta64[ns]'`` was incorrect (:issue:`17558`) | |||
- Bug in ``__setitem__`` when indexing a :class:`DataFrame` with a 2-d boolean ndarray (:issue:`18582`) |
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.
can you move to 0.23 (0.22 is a special release)
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.
Will do. Should hopefully have the time to finish this off this weekend...
pandas/tests/frame/test_indexing.py
Outdated
@@ -542,6 +541,16 @@ def test_setitem_boolean(self): | |||
np.putmask(expected.values, mask.values, df.values * 2) | |||
assert_frame_equal(df, expected) | |||
|
|||
def test_setitem_boolean_ndarary(self): |
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.
can you parametrize this
520adf7
to
0052a3a
Compare
0052a3a
to
96047f3
Compare
@jreback - should be good to go I think... |
pushed a change to the more common form of parametrization. ping on green. |
thanks @dhirschfeld ! |
Thanks for getting this over the line @jreback! |
git diff upstream/master -u -- "*.py" | flake8 --diff