-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
DEP: Drop deprecated boolean indexing behavior and update to new. #8312
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
Copied from post from @seberg. OK, this seems to do the trick:
|
c13e8a4
to
1265f86
Compare
@@ -714,7 +709,8 @@ def setUp(self): | |||
0, | |||
# Boolean indices, up to 3-d for some special cases of eating up | |||
# dimensions, also need to test all False | |||
np.array(False), | |||
# Fixme |
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.
@seberg, this test fails. Should it?
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.
Sure, the automated test, could probably be fixed, but we could even think about just removing this part since the other tests are more comprehensive nowadays.
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 had a glance at the code, I think I can probably fix it with two small modifications.
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 thought about removing it, not least because it is complicated.
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.
Good with me, it was very useful when there were not many tests, now its not awfully useful (hopefully). How about just removing this one case and maybe adding a comment that there is likely no point in supporting it indefinitely (could also move to its own file?). So that we can basically remove it whenever it should be too much trouble to tweak it?
Just am not sure if I like removing the test completely without a strong need. Who knows maybe it does test some things otherwise not tested, indexing is quite branched with many special cases.
@@ -1171,8 +1167,9 @@ def test_bool_as_int_argument(self): | |||
# array is thus also deprecated, but not with the same message: | |||
assert_raises(TypeError, operator.index, np.array(True)) | |||
assert_raises(TypeError, np.take, args=(a, [0], False)) | |||
assert_raises(IndexError, lambda: a[False, 0]) | |||
assert_raises(IndexError, lambda: a[False, 0, 0]) | |||
#fixme |
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.
@seberg these two tests fail, should they?
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.
The whole test should probably be replaced with new tests for the new behaviour. Sounds like it tests old behaviour
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.
Just wondering if the tested behavior was no longer valid. I seems that now booleans and integers can be mixed.
1265f86
to
a92e6ed
Compare
OK, I've removed the failing tests. This should be ready to go unless more tests are desired. |
Should probably add tests for some of the wonkier behaviour like :/
I can try to write more some time. |
Obviously all of those examples don't make any real sense at all, but they are valid combinations of the nonsense boolean indexing rules. |
a92e6ed
to
b005be2
Compare
OK, I added a |
@@ -2452,6 +2345,10 @@ mapiter_fill_info(PyArrayMapIterObject *mit, npy_index_info *indices, | |||
mit->fancy_dims[j] = 1; | |||
/* Does not exist */ | |||
mit->iteraxes[j++] = -1; | |||
if (mit->dimensions[mit->nd_fancy - 1] > 1) { |
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.
That test I guessed the result wrong... If its a True, its like a dimension of 1 and that means it can broadcast:
if ((indices[i].value == 0) && (mit->dimensions[mit->nd_fancy - 1] > 1)) {
should fix it. Wonky stuff mixing boolean arrays with other indexes....
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 guess the truth is, it is completely insane to do it anyway, but at least in my head there is a set of rules you can apply to get the result ;).
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.
Oh, I gave the wrong one, this is the one that fails:
a[True, [0, 1], True, True, [1], [[2]]]
Still need the fix?
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.
Yeah, I had pulled the PR to see the error message.
b005be2
to
2ac4537
Compare
OK, updated. |
LGTM. Its good to put this in early, who knows what problems might crop up. If you want I can try to write more tests some time, though could do that also after this is put in (could open an issue in that case I guess). Go ahead and put it in (or I can do it). |
Btw. thanks for taking care of all of this maintenance work! |
This affects mostly old boolean indexing behavior that was deprecated in NumPy 1.9. At the time the new behavior was causing errors in a number of downstream projects, hopefully that has been taken care of.
2ac4537
to
b80bcee
Compare
I've updated the release notes and will put this in. Thanks for the review. And of course more tests, and perhaps clarification in the release notes, are welcome ;) |
This affects mostly old boolean indexing behavior that was deprecated in NumPy 1.9. At the time the new behavior was causing errors in a number of downstream projects, hopefully that has been taken care of.