8000 GitHub · Where software is built
[go: up one dir, main page]

Skip to content
Going forward after numpy 2.0's change of copy semantics #16167
@neutrinoceros

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 ?

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

      0