ENH: add warning when calling ufunc with 'where' and without 'out'#29813
ENH: add warning when calling ufunc with 'where' and without 'out'#29813mhvk merged 5 commits intonumpy:mainfrom
Conversation
seberg
left a comment
There was a problem hiding this comment.
Thanks! I assume this is rare enough that introducing a warning is not a problem and it is very simple to remove the warning after all.
So I am in favor of trying this, approving, but the comments should be (mostly) addressed.
Test changes look good, the only ones I would worry about would be __array_wrap__ related, and those don't seem touched.
mhvk
left a comment
There was a problem hiding this comment.
Yes, nice; we really should have done this earlier...
Co-authored-by: Sebastian Berg <[email protected]>
mhvk
left a comment
There was a problem hiding this comment.
Nice! (I think my last comment was wrong, though)
|
Is it possible to add a stacklevel value to the warning, because it'd be nice to see the warnings caller. |
|
The warning already has the best possible stacklevel since it's in C (so no need to add one). But of course sometimes ufuncs are called indirectly (e.g. mean/var maybe). I am not sure if there is a nice way to add |
…umpy#29813) * add warning when calling ufunc with 'where' and without 'out' * DOC: add a release note Co-authored-by: Sebastian Berg <[email protected]>
…umpy#29813) * add warning when calling ufunc with 'where' and without 'out' * DOC: add a release note Co-authored-by: Sebastian Berg <[email protected]>
* the `out` and `where` args are both optional * however, if `where` is provided and `out` is not provided, then any values that evaluate to False in the `where` will be uninitialized * as of numpy-1.17.0 this will throw a warning, and our test suite is set to fail on warnings * see numpy/numpy#29813
* the `out` and `where` args are both optional * however, if `where` is provided and `out` is not provided, then any values that evaluate to False in the `where` will be uninitialized * as of numpy-1.17.0 this will throw a warning, and our test suite is set to fail on warnings * see numpy/numpy#29813
Closes #29804, related to # #17192, #29561 and maybe more
Users naively add a
whereargument without a properoutargument, and are surprised when theFalsevalues of the where mask are uninitialized. This PR adds a warning. The warning can be surpressed by usingwhere=mask, out=None. That came in handy in some obscure tests.