Skip to content

Going forward after numpy 2.0's change of copy semantics #16167

Description

@neutrinoceros

This issue is to track and discuss the follow up of #16142

Here's the context in a nutshell:

Here's a summary of old/new behaviors

copy numpy 1.x numpy 2.0
True always copy always copy (unchanged)
False copy if and only if it cannot be avoided do not perform a copy, raise an error if it cannot be avoided
None ValueError copy if and only if it cannot be avoided (same a False in numpy 1.x)

It follows that we cannot keep both the following implicit, and now conflicting, promises

  1. future astropy APIs (e.g. Quantity(..., copy=False)) will always match their past behavior
  2. astropy APIs follow numpy's

So we need to choose which one we care about most, and apply necessary transformations in that direction.
Another, equivalent, way to think about this choice is whether, going forward, we should support numpy 1 semantics or numpy 2 semantics.

I'm personally inclined to think 2) (follow numpy 2.0) should be preferred because

  • the new numpy API offers more flexibility to users (or in other words, numpy 1.x is too restrictive)
  • at some point in the future, no one will be running numpy 1.x any more so matching that API is guaranteed to surprise some users

So, assuming my preference is also consensual, let me draft out a plan for this pivoting. In the following,
I'll be referring to compatibility shims introduced in #16142 as "band aids"

  1. make the band aids redundant by refactoring our internal usage of numpy.array(..., copy=False) (this was originally part of BUG: fix compatibility with numpy 2.0 copy semantics #16142, and is re-rolled in RFC: refactor internal usage of copy=False to copy=COPY_IF_NEEDED #16166). I think this part is probably non-controversial as long as we don't attempt to backport it, so as it stands, it a pure refactor for astropy 6.1.0. This is needed in preparation to step 2 (avoid self-triggered warnings)
  2. deprecate band aids: warn users that copy=False will raise an error in the future if a copy cannot be avoided. The details of this deprecation will require further discussion1, but I think we can start working on it as soon as RFC: refactor internal usage of copy=False to copy=COPY_IF_NEEDED #16166 is dealt with.
  3. eventually, remove all band aids (this would be a major API change, so it can only happen in a x.0 release ?)

This discussion originated in #16142 (review) and #16142 (comment)

Footnotes

  1. when should it end ? do we want to warn all users or just the ones that are already on numpy >= 2.0 ? should we support some way to opt-in future behavior, and how ? ↩

Activity

  1. pllim commented on Mar 6, 2024

    @pllim
    Member

    Would it help to put this on the dev telecon agenda?

  2. neutrinoceros commented on Mar 6, 2024

    @neutrinoceros
    ContributorAuthor

    Yes, please ! I didn't think of that, thank you !

  3. pllim commented on Mar 7, 2024

    @pllim
    Member

    For the record, from 2024-03-07 dev telecon notes:

    • Consensus is to keep it simple: astropy shall match whatever the installed numpy version does. Avoid work to put in and later remove again compatibility layers, configuration options etc. Clément working on this.
    • Announce PR at astropy-dev mailing list when ready, so stakeholders like downstream pipeline maintainers can test it out to ensure no surprises later when numpy and/or astropy are released.
  4. neutrinoceros commented on Mar 8, 2024

    @neutrinoceros
    ContributorAuthor
  5. neutrinoceros commented on Mar 11, 2024

    @neutrinoceros
    ContributorAuthor

    I just sent out an email to astropy-dev to call for feedback on #16181

  6. neutrinoceros commented on Mar 15, 2024

    @neutrinoceros
    ContributorAuthor

    It was suggested that maybe we should backport this family of patches to astropy 6.0.x
    see #16181 (comment)

    At this point, the list, in merge order, includes

    I'm not so sure about #16198 (it's an actual API change), but I'm still considering the idea of backporting all of these manually in one bulk; not backporting them would mean that some of our users would see breakage when they upgrade astropy to 6.1.0. On the other hand, backporting puts the break on the upgrade to numpy 2.0 (where it logically belongs).

  7. neutrinoceros commented on Mar 15, 2024

    @neutrinoceros
    ContributorAuthor

    ⬆️ quoting from @taldcroft's reply in #16181 (comment)

    I really think we should only release all these changes in 6.1.0 and have a What's New.

    This should now be discussed in the following, broader scoped, issue : #16200

  8. neutrinoceros commented on Mar 26, 2024

    @neutrinoceros
    ContributorAuthor

    To anyone interested, I've opened a smaller related issue at #16235

  9. reopened this on Apr 3, 2024
  10. pllim commented on Apr 3, 2024

    @pllim
    Member

    I think merging #16252 closed this by accident, so re-opening.

    What are the remaining things needed to resolve this? Thanks!

  11. neutrinoceros commented on Apr 3, 2024

    @neutrinoceros
    ContributorAuthor

    #16181 is the last missing piece, I believe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions