-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
DEP: Deprecate boolean array indices with non-matching shape #4353
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
while it makes sense to me to deprecate it (you can always use slicing if you have a sparse bool mask) what do we gain by deprecating it? |
True, it adds quite a bit of code (could maybe restructure it a bit more, but won't change much). The gain is, that I really dislike this:
If nobody else minds that much, we can just leave it as is. |
@juliantaylor Just to clarify the example, currently
|
@seberg Needs a rebase. |
2e35648
to
af5f0bb
Compare
Rebased, removed release notes comment for now. Will have to go over this once more though. |
One useful thing I could now add (and maybe will), is to tell people that an array was original boolean when there is shape mismatch error. It won't be perfect, but better then nothing. |
b9dee35
to
59fde25
Compare
Seems like I would need to rebase this... So what is the take would a VisibleDeprecationWarning make sense? And would it be easy to give that from C? |
I like this, but am inclined to put it off to 1.11.0 unless there is agreement and @seberg has time. A VisibleDeprecationWarning would make sense, not sure of the easiest route to use it would be. Maybe define it in the Multiarray module? |
Will have to wait two weeks probably, but after that should be able to find some time. |
59fde25
to
35104c2
Compare
I have updated this to use VisibleDeprecationWarning which is imported on the fly when needed (we seem to do similar things for the Complex warnings), etc. However, I am not sure if this is quite right, and it might make sense to do the importing in the init instead of when the warning is given? |
@seberg I've passed this on to the mailing list if you want to weigh in. |
IMO the bizarre behavior of |
The consensus seems to be "yes", but I'll wait a bit longer. |
@seberg The |
d9e244f
to
8803dbd
Compare
Fixed that part (in the end, manually checked out the correct submodule branch during a rebase...). |
@@ -741,7 +744,8 @@ prepare_index(PyArrayObject *self, PyObject *index, | |||
/* | |||
* At this point indices are all set correctly, no bounds checking | |||
* has been made and the new array may still have more dimensions | |||
* then is possible. | |||
* then is possible. And boolean indexing arrays may have had a |
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.
then -> than
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.
"than is possible and boolean indexing arrays may have an incorrect shape."
if ((indices[i].type == HAS_FANCY) && indices[i].value > 0) { | ||
if (indices[i].value != PyArray_DIM(self, used_ndim)) { | ||
PyObject *m, *warning; | ||
|
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.
might as well remove this blank line and insert before sprintf
.
Mostly style stuff. There is not as much new code as I was led to believe. |
7b09f16
to
0247bda
Compare
Updated, justed the |
Boolean array indices will (unless the special case is taken) always be converted using a nonzero logic. However, for example ``` arr = np.arange(10) index = np.array([True]) arr[index] ``` would thus work as if index is filled up with `False`. This is a source of confusion and hardly useful in practice. Especially if the array has more then one dimension this behaviour can be very unexpected as it conflicts with broadcasting. Uses VisibleDeprecationWarning, since this is probably usually a user bug in the first place.
0247bda
to
c5ad058
Compare
DEP: Deprecate boolean array indices with non-matching shape
Thanks Sebastian. |
Boolean array indices will (unless the special case is taken)
always be converted using a nonzero logic. However, for example
would thus work as if index is filled up with
False
. This isa source of confusion and hardly useful in practice. Especially
if the array has more then one dimension this behaviour can
be very unexpected as it conflicts with broadcasting.