Skip to content

BUG: avoid deprecated interface for mutating shape attibutes (uncertainty) - #19131

Merged
neutrinoceros merged 1 commit into
astropy:mainfrom
neutrinoceros:uncertainty/19126
Jan 14, 2026
Merged

neutrinoceros merged 1 commit into
astropy:mainfrom
neutrinoceros:uncertainty/19126

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

ref #19126

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

github-actions Bot commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

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.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

docs failure are unrelated (#19134)
@pllim, would you be able to force merge this ?

@neutrinoceros
neutrinoceros marked this pull request as ready for review January 8, 2026 13:56
@pllim

pllim commented Jan 8, 2026

Copy link
Copy Markdown
Member

I could after uncertainty maintainer approves here. :)

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a bit trickier -- see inline comment. (Which also means it was useful to split them up, thanks!).

Comment thread astropy/uncertainty/core.py Outdated
structured.dtype = new_dtype
# Get rid of trailing dimension of 1.
structured.shape = samples.shape[:-1]
structured = np.reshape(structured, samples.shape[:-1])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go for using the private _set_shape method

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 method np.ndarray._set_shape.

So, this would be version dependent...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum okay maybe I just got confused. I'll try this again with a branch (tomorrow)

@neutrinoceros
neutrinoceros marked this pull request as draft January 12, 2026 11:36
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

trying this again using the semi-private ndarray._set_shape method (conditionally).

@neutrinoceros neutrinoceros changed the title BUG: avoid mutation of shape attibutes (uncertainty) BUG: avoid deprecated interface for mutating shape attibutes (uncertainty) Jan 12, 2026
@neutrinoceros
neutrinoceros marked this pull request as ready for review January 12, 2026 11:47
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

@mhvk @pllim I think this one should be prioritized now, it's by far the most impactful change needed in this area: this one line is responsible for about 150 tests failing and erroring.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@mhvk

mhvk commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Feel free to either merge or also fix the remaining masked errors associated with shape setting.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

I do prefer merging what we have now. Will open other targeted PRs. Hopefully the number of failures should become manageable very soon !

@neutrinoceros
neutrinoceros merged commit a99d198 into astropy:main Jan 14, 2026
31 of 33 checks passed
@lumberbot-app

lumberbot-app Bot commented Jan 14, 2026

Copy link
Copy Markdown

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v7.2.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 a99d1985cdb8b64810e0700d4af0b38d1955083d
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #19131: BUG: avoid deprecated interface for mutating shape attibutes (uncertainty)'
  1. Push to a named branch:
git push YOURFORK v7.2.x:auto-backport-of-pr-19131-on-v7.2.x
  1. Create a PR against branch v7.2.x, I would have named this PR:

"Backport PR #19131 on branch v7.2.x (BUG: avoid deprecated interface for mutating shape attibutes (uncertainty))"

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 Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@neutrinoceros
neutrinoceros deleted the uncertainty/19126 branch January 14, 2026 14:41
@pllim

pllim commented Jan 14, 2026

Copy link
Copy Markdown
Member

Are you able to do the manual backport part? Thanks!

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

yes. On it

neutrinoceros added a commit to neutrinoceros/astropy that referenced this pull request Jan 14, 2026
pllim added a commit that referenced this pull request Jan 14, 2026
Backport PR #19131 to branch v7.2.x (BUG: avoid deprecated interface for mutating shape attibutes (uncertainty))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants