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
Added fix for #16245 #16279
base: main
Are you sure you want to change the base?
Added fix for #16245 #16279
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.
|
Ideally the test python code (in #16245) should also be included with this fix. |
This fix looks good but I can investigate the test failure tomorrow. Looks puzzling at first glance! |
The failure is related, it seems to be related to the fact if e.g. crval is modified in place then flag doesn't get reset. I need to look more closely to understand why set() would change results in that case though. |
Huh - that's weird. |
I think this specific example changes one element of the array in-place so I'm not sure if the setter gets called? |
Based on this SO post (and a couple of others I read) seems that the setter does not get called if an element of the array is modified in-place. The only way that functionality could happen is through adding One option is to move the change back to |
In comments:
I really would like to know Mark's opinion on this. Why wasn't this check implemented in |
Yeah agreed. In an email with Tom and me, Mark said that such
Moving the fix to |
BTW, the unit test that's failing, |
That's good to know! I do not have the context to know that :) |
context is exactly the same as in #16279 (comment): "setter does not get called if an element of the array is modified in-place". This was brought up numerous times in the past although I cannot find past discussions. Related to the failing test, I am not sure that changing wcs.wcs.crval[0] = 0 to wcs.wcs.crval[0] = 0
wcs.wcs.set() OR wcs.wcs.crval = [0, *wcs.wcs.crval[1:]] would solve the failure. |
Probably if this PR is merged, something like this will not work: w = WCS()
w.wcs.ctype = ['RA---TAN', 'DEC--TAN']
w.wcs.ctype[1] = 'GLON--TAN'
w.wcs.ctype[0] = 'GLAT--TAN'
assert w.wcs.lattyp == 'GLAT' Now one will have to call |
I meant I lacked the context for what would be considered reasonable user behaviour (and not the code context).
This PR should not be merged at this stage. We need to develop a better fix that allows the user to update individual items. |
After some digging around, I see that these lines within
Since the setters are not invoked when changing a single element, |
One way to detect whether any field has changed could be to store a hash value of the contents of the relevant fields (and ignoring memory addresses). If a change is detected, then Another option could be to allow user access to |
Another option on the astropy side might be to use a numpy array subclass to store the wcsprm elements so that we can correctly set the flag if individual items are set? |
Noting the reproducer here as well: https://gist.github.com/manodeep/23e5a2cc037752ce861bdb2998314137 |
That is beyond my python / astropy expertise. |
Description
This pull request fixes #16245