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
Don't return Quantities from high_level_objects_to_values #16287
base: main
Are you sure you want to change the base?
Don't return Quantities from high_level_objects_to_values #16287
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.
|
👋 Thank you for your draft pull request! Do you know that you can use |
…re that units are converted on quantities
@Cadair @nden I've updated this to actually just check the input/output types of the high level <-> values functions rather than silently dropping quantity-ness if present. I think it makes sense to be somewhat strict here otherwise introducing quantities into this can cause confusion and errors. This would have caught invalid WCSes like spacetelescope/gwcs#495 at least when used via SlicedLowLevelWCS. |
a72b00c
to
4f7c216
Compare
# Check the type of the return values - should be scalars or plain Numpy | ||
# arrays, not e.g. Quantity. Note that we deliberately use type(w) because | ||
# we don't want to match Numpy subclasses. | ||
for w in world: |
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.
Will this have performance impact? 🤔
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 very much doubt it, it's only looping over a couple (or maybe up to 5) dimensions - not over each individual value of a large array
FWIW benchmark isn't affected but I also don't know if you have benchmarks for WCS APIs.
|
The
high_level_objects_to_values
function should not be returning quantities because otherwise this is resulting in quantities being passed through toworld_to_pixel_values
which should not happen (only bare scalars/arrays should be used).I have also added a conversion of units to
world_axis_units
but I'm not sure if we should. This is a possible pragmatic solution to the fact that some WCSes might defineworld_axis_object_components
in a way that is inconsistent withworld_axis_units
, such as in spacetelescope/gwcs#495 - however, if all the metadata was defined correctly this should not be needed. So another option is to be strict here and simply replace.to_value()
by.value
.I still need to add a test for this, will do once we agree on the approach.