Repository navigation
Added astropy.units.quantity_overload decorator which allows instances of Quantity to be used with functions designed to accept only instances of ndarray. - #19024
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
I really didn't want to add the new |
|
I think it may be reasonable to add it as a dev-only dependency using a dependency group, but in any case it should come with an explicit lower bound on the requirement. |
|
Adding numba just to test one thing seems a bit of an overkill? I use my dev env for many things. I am not excited to have to install numba just to run this test. |
|
You would only need to install it to run this test, not to run any other part of the test suite. Is this still too much ? |
|
We also have to think about all the flavors of CI jobs that would be required to pull it in. CI is red anyway. |
|
@mhvk, do you understand why For example, if I do I get the error even though the function This obviously all works if I use |
|
|
neutrinoceros
left a comment
There was a problem hiding this comment.
I just took a look at why CI is red and it may be a little confusing, but the short answer is we'll need to somehow isolate the test so it doesn't permanently affect the global state of the registry.
Indeed, I think you need some kind of p.s. Sorry, haven't had a chance to actually look at the code... (end of term time, so lots of exams to give...). |
|
I can probably provide a custom pytest fixture to handle setup and teardown. Any way, just something to keep in mind. |
|
@neutrinoceros and @mhvk, if you changed to wouldn't that preserve the spirit of the test and allow the tests to pass? |
|
No, definitely not OK. I would want to know if there are "wrong" ufuncs registered. But it is not hard to do the setup/teardown; let's first focus on the actual code (for me, not before the weekend, sorry!) |
|
No worries, enjoy your weekend! |
astropy.units.quantity_ufunc_overload decorator which converts instances of Quantity to instances of ndarray for use with user-defined numpy ufuncs.astropy.units.quantity_overload decorator which allows instances of Quantity to be used with functions designed to accept only instances of ndarray.
|
I realized that registering new ufuncs was probably unnecessary. The same behavior can be accomplished by writing a decorator which strips the units off of the arguments and then attaches the units after the numpy function is complete. This fixes the issue around needing setup/teardown methods for the |
|
@roytsmart - sorry still not had time to look properly... But the idea to make it more general is certainly nice (even if it effectively becomes a different beast). Indeed, with it I think you are going to close a couple of long-standing issues: #7368 and #6007 (latter, indirectly, by having a different way to do it), |
|
@mhvk, that's great that this addresses some long-standing issues. I think this way is going to work much better. Unfortunately, we won't be able to fix #6007 yet since |
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in a month if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
…its, pass the vanilla numpy arrays into the function, and then reattach the units after.
2928196 to
8d71553
Compare
|
Agreed, this would still be useful for me as well. I just rebased onto main so we can see if everything still works. |
|
I think the devdeps failures are related.
|
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in a month if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
Description
This pull request is to address ...
Fixes #19005