Skip to content

numpy 2.0: a possible API inconsistency in numpy.ndarray.astype (copy semantics) ? #25925

Closed

Description

@neutrinoceros

As I'm adapting astropy to the new copy semantics from #25168 and #25922, I observe that numpy.ndarray.astype wasn't updated to follow these changes. As a result, it still supports the old semantics where copy=False means "copy only if you must" but never raises an error. Is that intended ?

numpy.astype, introduced in #25079, is also affected by this question.

Activity

  1. added this to the 2.0.0 release milestone on Mar 4, 2024
  2. rgommers commented on Mar 4, 2024

    @rgommers
    Member

    @neutrinoceros thanks for the question. Yes, this was intentional, since there wasn't too much appetite for changing the behavior of copy=False given that astype explicitly casts to a different dtype - and that usually cannot be done without a copy. It's noted in NEP 56: https://numpy.org/neps/nep-0056-array-api-main-namespace.html#copy-keyword-semantics.

    I checked that astype does accept all of True/False/None. False just doesn't mean "never copy". Does that seem reasonable?

  3. neutrinoceros commented on Mar 4, 2024

    @neutrinoceros
    ContributorAuthor

    Absolutely ! Just wanted to check with you before the first release candidate if I could :)
    Let's just close this then. Good luck with the release !

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions