Repository navigation
Backport PR #19129 on branch v7.2.x (BUG: avoid mutation of shape attibutes (modeling)) - #19150
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.
|
| param = np.reshape(param, (5,)) | ||
| # Reshape success | ||
| param.shape = (2, 2) | ||
| param = np.reshape(param, (2, 2)) |
There was a problem hiding this comment.
@mhvk what is the correct way to fix this? This is not correct because then param.value will error out. I think we missed this on main. I was hoping to fix in the backport and then forward port the backport fix...
There was a problem hiding this comment.
Hmm, I think this change was a mistake. Param is not a subclass of ndarray so in principle it can have different semantics. The quick-fix solution would be to keep setting the shape here in the tests, and inside the setter for Parameter.shape use np.reshape -- this is at:
astropy/astropy/modeling/parameters.py
Lines 461 to 467 in dc7afdd
Longer term, I think we should implement __array_function__ on Parameter, or, maybe better, have it inherit from ShapedLikeNDArray and define an appropriate _apply. With that, functions like np.reshape, np.ravel, etc., will just work.
There was a problem hiding this comment.
Thanks! I think that works great, at least when testing locally.
Can you please review the whole diff in this PR and see if they all still make sense altogether? 🙏
03447d3 to
2f86fad
Compare
|
Maybe there's been a misunderstanding. I never said #19129 would fix all errors in |
|
done in #19152 |
2f86fad to
723548c
Compare
|
Yes, you caught me being lazy. Thanks for the proper follow-up! |
Backport PR #19129: BUG: avoid mutation of shape attibutes (modeling)