Skip to content

BUG: fix np.array's dispatcher for compatibility with numpy 2.4 - #18841

Merged
neutrinoceros merged 1 commit into
astropy:mainfrom
neutrinoceros:bug/compat-numpy-2.4-c
Nov 6, 2025
Merged

neutrinoceros merged 1 commit into
astropy:mainfrom
neutrinoceros:bug/compat-numpy-2.4-c

Conversation

@neutrinoceros

@neutrinoceros neutrinoceros commented Nov 6, 2025 •

Copy link
Copy Markdown
Contributor

Description

xrefs:

Again here, I'm ahead on numpy nightlies, so this problem shouldn't be visible on unstable CI before Sunday or Monday. Hopefully the small issue I reported and patched upstream (see xrefs) is resolved in the mean time
update: done

  • 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 Nov 6, 2025

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.

@github-actions

github-actions Bot commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

Welcome to Astropy 👋 and congratulations on your first pull request! 🎉

A project member will respond to you as soon as possible; in the meantime, please have a look over the Checklist for Contributed Code and make sure you've addressed as many of the questions there as possible.

If you feel that this pull request has not been responded to in a timely manner, please send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

@github-actions

github-actions Bot commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@neutrinoceros neutrinoceros added the Upstream Action Required Was: Upstream Fix Required label Nov 6, 2025
@neutrinoceros
neutrinoceros force-pushed the bug/compat-numpy-2.4-c branch from ef98ccd to ac63d76 Compare November 6, 2025 12:01
@neutrinoceros neutrinoceros removed the Upstream Action Required Was: Upstream Fix Required label Nov 6, 2025
@neutrinoceros
neutrinoceros force-pushed the bug/compat-numpy-2.4-c branch from ac63d76 to 7766b19 Compare November 6, 2025 12:05
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

oh that's fun: because this only adds an argument to an existing function, it's not rejected by CI even though the corresponding change hasn't landed in a numpy nightly yet. This is because our signature checks are intentionally lenient about wrappers being more flexible that wrapped functions (they just cannot be any stricter). Maybe that could eventually create blindspots, and I'll probably end up opening a dedicated issue about that, but in the mean time, I think I'll just open this for review now, since it can apparently be merged immediately without breaking CI !

@neutrinoceros
neutrinoceros marked this pull request as ready for review November 6, 2025 15:49
@neutrinoceros
neutrinoceros requested a review from mhvk November 6, 2025 15:50

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

Some suggestions, but really it does not matter, so I will approve now and let you decide whether just to merge what you have, or to follow one of my suggestions.

)


def array_impl(object, *, dtype, copy, order, subok, ndmin, ndmax=0):

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'd tend to write the implementation just as

def array_impl(object, **kwargs):
   out_unit = getattr(object, "unit", UNIT_FROM_LIKE_ARG)
    if out_unit is not UNIT_FROM_LIKE_ARG:
        object = _as_quantity(object).value
    return (object,), kwargs, out_unit, None

Alternatively, write it as it will be with numpy >=2.4, and then do

if not NUMPY_LT_2_4:
    array = function_helper(array_impl)

else:
    @function_helper
    def array(object, dtype=None, *, copy=True, order="K", subok=False, ndmin=0):
        return array_impl(
            object, dtype=dtype, copy=copy, order=order, subok=subok, ndmin=ndmin
        )

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.

in any case the difference will factor itself out in the future, so indeed, it shouldn't really matter. Since I'm not near a keyboard right now, I'd rather just merge as is. But I'll try to keep this in mind next time, thanks !

@neutrinoceros
neutrinoceros merged commit 3a52bad into astropy:main Nov 6, 2025
4 checks passed
@neutrinoceros
neutrinoceros deleted the bug/compat-numpy-2.4-c branch November 6, 2025 16:47
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Nov 6, 2025
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.

2 participants