Skip to content

BUG: avoid deprecated interface for mutating shape attibutes (io.fits) - #19128

Merged
pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:io.fits/19126
Jan 14, 2026
Merged

pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:io.fits/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

I dropped part of the patch that turned out to break backward compat. This PR is just aimed at getting trivial changes out of the way so we can focus discussions where needed, so the remaining patch will get a dedicated issue.

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

I worried slightly about changing the purpose of the test, since how an actual assignment to .data is done, which may trigger a different path. I'd tend to just go for the private method to set the shape, but maybe @saimn can advice.

@neutrinoceros
neutrinoceros marked this pull request as ready for review January 8, 2026 16:53
@neutrinoceros
neutrinoceros requested a review from saimn as a code owner January 8, 2026 16:53
@saimn

saimn commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Yeah, as Marten says it changes a bit what happens internally. So if we want to keep the test unchanged we need to use the new _set_data method but then this restricts this part of the test to the new Numpy version. It is probably also interesting to test with .data = ... since this is what users will use and I'm not sur if this is tested elsewhere.

@braingram

Copy link
Copy Markdown
Contributor

Does it make sense to update:

b.shape = -1, b.shape[-1]

as part of this PR?

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

we need to use the new _set_data method but then this restricts this part of the test to the new Numpy version. It is probably also interesting to test with .data = ... since this is what users will use and I'm not sur if this is tested elsewhere.

Maybe there's a bit of confusion going on here, at least in the form of typing mishaps, because _set_data isn't a thing (the private method we can use is ndarray._set_shape). As a result, I'm not entirely sure what you meant.
I'll push an update with my best guess but let me know if I got it wrong !

@neutrinoceros
neutrinoceros force-pushed the io.fits/19126 branch 2 times, most recently from 67b9ab7 to 2ef5cdc Compare January 13, 2026 09:26
@neutrinoceros neutrinoceros changed the title BUG: avoid mutation of shape attibutes (io.fits) BUG: avoid deprecated interface for mutating shape attibutes (io.fits) Jan 13, 2026
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

@braingram absolutely. I initially left it out intentionally because I was worried the discussion there would be thorny, especially because I wasn't sure others would be okay with resorting to _set_shape, but I think now that it makes total sense there so I just included it here. Thanks for pointing it out again !

@saimn

saimn commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

@neutrinoceros - Yes _set_shape, sorry. We should test inplace shape modification (with _set_shape for numpy ≥ 1.25) so that the test is unchanged, and could also test (with a new block) that setting data works the same way since I'm not sure if this is tested elsewhere (and this is what users would do).

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

how about now ?

Comment thread astropy/io/fits/tests/test_image.py Outdated
if NUMPY_LT_2_5:
hdul[0].data.shape = (42, 10)
else:
# ndarray._set_shape would is semi-private, but the only

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.

Suggested change
# ndarray._set_shape would is semi-private, but the only
# ndarray._set_shape is semi-private, but the only

@saimn

saimn commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

how about now ?

Looks good, thanks (just a minor typo).

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

thank you. Fixed

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

Yes, looks good!

@pllim

pllim commented Jan 14, 2026

Copy link
Copy Markdown
Member

You wanna rebase one more time, just in case?

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

done

@pllim

pllim commented Jan 14, 2026

Copy link
Copy Markdown
Member

Thanks! No need for wait for OSX.

Down to 46 warnings/failures and looks like coordinates is the next big one. 🤪

@pllim
pllim merged commit 72e9a26 into astropy:main Jan 14, 2026
30 of 33 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Jan 14, 2026
@neutrinoceros
neutrinoceros deleted the io.fits/19126 branch January 14, 2026 17:30
pllim added a commit that referenced this pull request Jan 14, 2026
…128-on-v7.2.x

Backport PR #19128 on branch v7.2.x (BUG: avoid deprecated interface for mutating shape attibutes (io.fits))
tonybaloney pushed a commit to tonybaloney/swe-complex-astropy that referenced this pull request Mar 19, 2026
tonybaloney pushed a commit to tonybaloney/swe-complex-astropy that referenced this pull request Mar 19, 2026
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.

5 participants