Skip to content

numeric exceptions in simple functions #17466

@BishopWolf

Description

@BishopWolf

Numeric types shall be self contained and automatically typecasted

Reproducing code example:

import numpy as np
a = np.array([1, 1, 1, 1, 1])
a += 0.1

expected behaviour:

a is typecasted to float64 automatically before doing the add function. The following code works:

import numpy as np
a = np.array([1., 1., 1., 1., 1.])
a += 0.1

it returns array([1.1, 1.1, 1.1, 1.1, 1.1]). This shall be the returning value of the code above.

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

NumPy/Python version information:

1.19.1 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions