Skip to content

BUG: creating an integer scalar from a string does not warn about overflow #24066

@ngoldbaum

Description

@ngoldbaum

This behavior is deprecated:

in [3]: np.int32(2147483648)
<ipython-input-3-cd4bcbe47c5d>:1: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 2147483648 to int32 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)
will give the desired result (the cast overflows).
  np.int32(2147483648)
Out[3]: -2147483648

But this doesn't warn and probably should for consistency:

In [4]: np.int32('2147483648')
Out[4]: -2147483648

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