BUG/DEP: Make ufunclike functions more ufunc-like#8996
Conversation
6618d12 to
3a1e139
Compare
3a1e139 to
6c06883
Compare
There was a problem hiding this comment.
For a little more efficiency, we could change this to:
nx.logical_and(nx.isinf(x, out), nx.signbit(x), out)
But that seemed out of scope for the bugfix/deprecation
6c06883 to
e4f2726
Compare
|
Ugh, this was much messier than intended - turns out that #8994 is a much bigger stumbling block to making things work right than expected. |
e4f2726 to
20b49ad
Compare
20b49ad to
d2f35b6
Compare
There was a problem hiding this comment.
Previous commit forgot to specify a stacklevel
|
(Since there's some subclass trickery going on here, and you've had opinions on |
mhvk
left a comment
There was a problem hiding this comment.
Looks good except for the one comment; I don't think we should introduce a new where here.
Separately, I see now really good use for my plans to get chained ufuncs to work...
There was a problem hiding this comment.
The version of where you have above is not subclass-safe, at least not for Quantity (where, in general, the two arrays might have different units). For this particular function, it might nevertheless work, but I would suggest not introducing a new function. Instead, perhaps the following (I checked it passes all tests):
out = nx.asanyarray(nx.floor(x, out=out))
out = nx.ceil(x, out=out, where=(x < 0))
return out if out.shape else out[()]
There was a problem hiding this comment.
This should be out if type(out) != np.ndarray or out.shape else out[()], I think.
There was a problem hiding this comment.
It should be whatever is closest to what a ufunc does; any subclasses should be able to deal with out[()]... (I guess the alternative would be to separate out the non-array case, but that seems overkill)
There was a problem hiding this comment.
Yep, ufuncs only unpack scalars on the base classes, presumably as subclasses might lose metadata
There was a problem hiding this comment.
Alright, fixed I think - it was a little bit messier than that
There was a problem hiding this comment.
And one more time, with tests for the cases that your suggestion didn't cover
d2f35b6 to
6e2424b
Compare
No need to reinvent the wheel here - the ufunc machinery will handle the out arguments Fixes numpy#8993
6e2424b to
05f4228
Compare
|
Looks all OK now! |
|
Could probably add the |
|
I'm happy with this. @charris - do you want to have another look, or is this ready to go in? |
|
@mhvk I didn't really review, just glanced over it and thought it was generally good. Put it in if you like it. |
|
OK, merged! Thanks, @eric-wieser! |
This fixes #8993 and #8995