Skip to content

Scalar astype method doesn't accept keyword arguments #9512

@bmerry

Description

@bmerry

According to the docs, numpy scalars are supposed to have the same methods as arrays, but the astype method behaves differently by not accepting keyword arguments. This can cause issues for code that wants to accept scalars and arrays interchangeably e.g. see thunder-project/thunder#121 (not my use case, just the first hit I found).

Sample code (numpy 1.13.1):

>>> import numpy as np
>>> np.float64(1).astype(np.float32, casting='same_kind')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: astype() takes no keyword arguments

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