Repository navigation
BUG: avoid deprecated interface for mutating shape attibutes (uncertainty) - #19131
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.
|
de70cbd to
eb0f387
Compare
|
I could after uncertainty maintainer approves here. :) |
mhvk
left a comment
There was a problem hiding this comment.
This one is a bit trickier -- see inline comment. (Which also means it was useful to split them up, thanks!).
| structured.dtype = new_dtype | ||
| # Get rid of trailing dimension of 1. | ||
| structured.shape = samples.shape[:-1] | ||
| structured = np.reshape(structured, samples.shape[:-1]) |
There was a problem hiding this comment.
I think this is one case where it is not unreasonable to just set the shape, since we really just created the array and are full owners of it. If we keep the reshape, we certainly should add copy=False (which I think is available in all versions, not sure), since it is a bug if a copy would need to get made.
Personally, I'd go for using the private _set_shape method here -- we'll have to do the same with the dtype later...
There was a problem hiding this comment.
copy=False (which I think is available in all versions, not sure)
the copy kwarg was only introduced in numpy 2.1, so I can't use it without branching.
There was a problem hiding this comment.
I'd go for using the private
_set_shapemethod
I meant to ask: is it a method on the ndarray class ? when was it introduced ? my attempt to use it with numpy dev was unsuccesful (got an AttributeError), so I think I'm missing some context.
There was a problem hiding this comment.
From the changelog entry: https://github.com/numpy/numpy/pull/29536/files#diff-fdbbec0927064b4f5de50467962cad77f4225ba28c9bfbcb2ef16e73e3acda8e
Directly setting the shape on an array is discouraged, but for cases where it is difficult to work
around, e.g., in__array_finalize__possible with the private methodnp.ndarray._set_shape.
So, this would be version dependent...
There was a problem hiding this comment.
hum okay maybe I just got confused. I'll try this again with a branch (tomorrow)
eb0f387 to
6274f4f
Compare
|
trying this again using the semi-private |
6274f4f to
5c22ea8
Compare
mhvk
left a comment
There was a problem hiding this comment.
Thanks for the reminder: the current change is great. I think we eventually want to move away from setting the shape directly this way, but now we can do it calmly, in due time!
mhvk
left a comment
There was a problem hiding this comment.
This certainly seems right even if it doesn't fix all errors yet (see below), so I think we should get it in.
Note: the logs are now clipped by default; I think we should not use --verbose for pytest, so that we can be sure we always get the final summary and don't have to go to the raw logs to see it.
2026-01-12T11:59:22.2662642Z �[31mFAILED�[0m ../../.tox/py313-test-devdeps/lib/python3.13/site-packages/astropy/utils/masked/tests/test_function_helpers.py::�[1mTestArraySetOps::test_isin[int]�[0m - DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
2026-01-12T11:59:22.2663697Z As an alternative, you can create a new view using np.reshape (with copy=False if needed).
2026-01-12T11:59:22.2665154Z �[31mFAILED�[0m ../../.tox/py313-test-devdeps/lib/python3.13/site-packages/astropy/utils/masked/tests/test_function_helpers.py::�[1mTestArraySetOps::test_isin[float]�[0m - DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
2026-01-12T11:59:25.4150085Z As an alternative, you can create a new view using np.reshape (with copy=False if needed).
2026-01-12T11:59:25.4153645Z �[31mFAILED�[0m ../../.tox/py313-test-devdeps/lib/python3.13/site-packages/astropy/utils/masked/tests/test_function_helpers.py::�[1mTestArraySetOps::test_isin[object]�[0m - DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
2026-01-12T11:59:25.4156000Z As an alternative, you can create a new view using np.reshape (with copy=False if needed).
2026-01-12T11:59:25.4158470Z �[31mFAILED�[0m ../../.tox/py313-test-devdeps/lib/python3.13/site-packages/astropy/utils/masked/tests/test_function_helpers.py::�[1mTestArraySetOps::test_setdiff1d�[0m - DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
2026-01-12T11:59:25.4160369Z As an alternative, you can create a new view using np.reshape (with copy=False if needed).
2026-01-12T11:59:25.4161961Z �[31mFAILED�[0m ../../.tox/py313-test-devdeps/lib/python3.13/site-packages/astropy/utils/masked/tests/test_masked.py::�[1mTestMaskedNDArraySubclassCreation::test_viewing_independent_shape�[0m - DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
2026-01-12T11:59:25.4163169Z As an alternative, you can create a new view using np.reshape (with copy=False if needed).
2026-01-12T11:59:25.4164505Z �[31mFAILED�[0m ../../.tox/py313-test-devdeps/lib/python3.13/site-packages/astropy/utils/masked/tests/test_masked.py::�[1mTestMaskedArrayShaping::test_shape_setting�[0m - DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
2026-01-12T11:59:25.4165852Z As an alternative, you can create a new view using np.reshape (with copy=False if needed).
2026-01-12T11:59:25.4167197Z �[31mFAILED�[0m ../../.tox/py313-test-devdeps/lib/python3.13/site-packages/astropy/utils/masked/tests/test_masked.py::�[1mTestMaskedArrayShaping::test_shape_setting_failure�[0m - DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
2026-01-12T11:59:25.4168507Z As an alternative, you can create a new view using np.reshape (with copy=False if needed).
|
Feel free to either merge or also fix the remaining |
|
I do prefer merging what we have now. Will open other targeted PRs. Hopefully the number of failures should become manageable very soon ! |
|
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
|
Are you able to do the manual backport part? Thanks! |
|
yes. On it |
(cherry picked from commit a99d198)
Backport PR #19131 to branch v7.2.x (BUG: avoid deprecated interface for mutating shape attibutes (uncertainty))
Description
ref #19126