Skip to content

Stop hiding numpy.msort() deprecation warnings with Masked arrays - #18173

Merged
mhvk merged 2 commits into
astropy:mainfrom
eerovaher:np-msort-deprecation
May 26, 2025
Merged

mhvk merged 2 commits into
astropy:mainfrom
eerovaher:np-msort-deprecation

Conversation

@eerovaher

Copy link
Copy Markdown
Member

Description

numpy.msort() was deprecated in 1.24 and removed in 2.0, but despite that no warnings are emitted if the function is called with a Masked array. The first commit here reveals the bug, the second fixes it.

The reason this went unnoticed was that the function that checks np.msort() with a Masked array is skipped entirely unless the installed numpy version is <1.24, where the function was not deprecated. We do have machinery that tries to check for the completeness of relevant tests, but that machinery only checks that an appropriate test function exists, not that it is called (which also has the charming consequence that removing a test that is always skipped can cause other tests to fail).

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

eerovaher added 2 commits May 23, 2025 16:08
`numpy.msort()` was deprecated in version 1.24 and removed in 2.0. The
updated test demonstrates that `astropy` erroneously hides the
deprecation message if `msort()` is called with a `Masked` array.
Calling `numpy.msort()` with a `Masked` array no longer hides the
deprecation message (with `numpy` 1.24-1.26).
@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.

Comment on lines +575 to +577
warnings.warn(
"msort is deprecated, use np.sort(a, axis=0) instead",
DeprecationWarning,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is missing a stacklevel, but the call goes through <__array_function__ internals>, which apparently destroys Python's ability to do anything sensible with the stacklevel. This warning is only displayed for users that have astropy > 7.1.0 together with 1.24 <= numpy < 2.0. I would imagine most users have either a recent version of both or an old version of both, so the number of people that have the potential of seeing this warning is small enough that the stacklevel is not worth worrying about too much.

@pllim

pllim commented May 23, 2025

Copy link
Copy Markdown
Member

I don't think we should backport this. Nothing is really broken and extra warning in bugfix release would surprise people. Thanks for your understanding.

@pllim pllim modified the milestones: v7.1.1, v7.2.0 May 23, 2025

@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 catching that. I guess the underlying problem is that, unusually, this helper does not actually call the underlying function directly. Which in turn is probably because it was one of those functions I didn't even know about, but which turned up when we started to try to be sure that we covered all functions.

Anyway, let's get this in (I agree with @pllim on not backporting).

@mhvk
mhvk merged commit ed95105 into astropy:main May 26, 2025
@eerovaher
eerovaher deleted the np-msort-deprecation branch May 26, 2025 13:10
@eerovaher eerovaher mentioned this pull request May 26, 2025
1 task done
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