Skip to content

BUG: avoid deprecated shape mutation APIs in time - #19182

Merged
mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:time/19126
Jan 22, 2026
Merged

mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:time/19126

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

ref #19126

opening as a draft: what I have seem necessary but not sufficient. Will provide more details later

  • 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

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

ok so I added an experimental commit that should help bringing more context; The problem I'm currently facing is that the remaining failing test contains several fragile parts that I don't immediately know what to do with

  • there's a with pytest.raises(AttributeError) which I believe is expecting an exception that we don't really control (I amended it in my latest commit)
  • later on, we test what happens for in place mutations that expect automatic broadcasting: this isn't replicable with np.reshape, ndarray.reshape or ndarray._set_shape, as far as I understand. The only path forward that I'm seeing would be to skip this part of the test for numpy 2.5+ and somehow deprecate/drop support for this pattern later if we can.

Any insight here, @mhvk ?

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

(Also I think image test failures are unrelated)

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

note that the problem I'm facing here is similar to #19133

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

@neutrinoceros - this basically looks good. Let me know when you take it out of draft.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

I was actually waiting for early feedback from you. The change may be sensible but it isn't stable: there's still one test failing, and the failure mode is new in this PR

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

@neutrinoceros - I think I found the problem...

Comment thread astropy/time/core.py
if val is None or val.size <= 1:
continue
try:
if NUMPY_LT_2_5:

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.

The problem is here: you assume that all val will be ndarray subclasses where _set_shape will just work, but for Masked subclasses this does not change the shape of the mask. I think we need to adjust MaskedNDArray -- see comment below.

p.s. I don't quite recall the failure modes for other parts, but possibly the assumption that every attribute is a plain ndarray goes wrong there too.

@@ -744,13 +745,22 @@ def shape(self):
@shape.setter
def shape(self, shape):

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.

As noted above, for not NUMPY_LT_2_5we also need to override _set_shape since it does not go the correct thing. Possibly easiest is just to call this _set_shape and let shape.setter refer to it.

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.

THANK YOU ! this is exactly correct, and does resolve the remaining failure.

Comment thread astropy/utils/masked/core.py Outdated
if NUMPY_LT_2_5:
super(MaskedNDArray, type(self)).shape.__set__(self, shape)
else:
self._set_shape(shape)

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.

Since we need to define our own _set_shape, this needs to be super()._set_shape(shape).

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

Great that it worked! Let's get it in.

@mhvk
mhvk enabled auto-merge January 22, 2026 18:46
@pllim

pllim commented Jan 22, 2026

Copy link
Copy Markdown
Member

And the remaining 33 requires jplephem release or something? What is the wait time on that? Should we put in a ignore filter for now?

@mhvk

mhvk commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

Yes, ignoring the jplephem warnings (or, really, anything outside of astropy and numpy, if we can do that...) would make a lot of sense.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

And the remaining 33 requires jplephem release or something?

yes

What is the wait time on that?

No idea.

ignoring the jplephem warnings (or, really, anything outside of astropy and numpy, if we can do that...)

I don't think pytest (really, warnings) supports this, but we could temporarily use my fork of jplephem in CI (as I did in #19184) to achieve the same effect.

@mhvk
mhvk merged commit 081b25b into astropy:main Jan 22, 2026
31 of 33 checks passed
@pllim

pllim commented Jan 22, 2026

Copy link
Copy Markdown
Member

I mean, just ignore the entire "Setting the shape on a NumPy array has been deprecated" in pyproject.toml here:

filterwarnings = [

with a follow-up issue to remove the ignore before next v7.2.x release by setting a milestone to the issue.

@lumberbot-app

lumberbot-app Bot commented Jan 22, 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 081b25b00ffc41cd4ee728f8011dcaef5cd56d2e
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #19182: BUG: avoid deprecated shape mutation APIs in time'
  1. Push to a named branch:
git push YOURFORK v7.2.x:auto-backport-of-pr-19182-on-v7.2.x
  1. Create a PR against branch v7.2.x, I would have named this PR:

"Backport PR #19182 on branch v7.2.x (BUG: avoid deprecated shape mutation APIs in time)"

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.

@pllim

pllim commented Jan 22, 2026

Copy link
Copy Markdown
Member

Also can you please manually backport? Thanks! 🙏

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

I mean, just ignore the entire "Setting the shape on a NumPy array has been deprecated" in pyproject.toml here:

I know it's closer to our usual workflow, but I also think it's riskier in this instance: we could easily silence a real warning from ourselves or another third party library.

Anyway, best case scenario is still that we don't need a workaround at all.
Will manually backport this now

@neutrinoceros
neutrinoceros deleted the time/19126 branch January 22, 2026 20:15
neutrinoceros pushed a commit to neutrinoceros/astropy that referenced this pull request Jan 22, 2026
BUG: avoid deprecated shape mutation APIs in time
(cherry picked from commit 081b25b)
pllim added a commit that referenced this pull request Jan 22, 2026
Backport PR #19182 to branch v7.2.x (BUG: avoid deprecated shape mutation APIs in time)
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.

3 participants