Skip to content

BUG: np.astype(copy=False) copies for scalars #29455

@alippai

Description

@alippai

Describe the issue:

There is difference in scalar vs array handling of .astype(copy=False), arrays work as expected

Reproduce the code example:

import numpy as np
b = np.float64(1.1)
id(b), id(b.astype('float64', copy=False))
(140737303069360, 140737303069584)
id(b), id(np.astype(b, 'float64', copy=False))
(140737303069360, 140737303069424)
c = np.array([1.1], dtype='float64')
id(c), id(np.astype(c, 'float64', copy=False))
(140737302772592, 140737302772592)

Error message:

Python and NumPy Versions:

2.1.3
3.13.3 | packaged by conda-forge

Runtime Environment:

No response

Context for the issue:

No response

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