Skip to content

full and full_like permit out-of-bounds Python integers #27075

@ndgrigorian

Description

@ndgrigorian

full and full_like permit out-of-bounds Python integers, which is inconsistent as of Numpy 2.0.

In [2]: import numpy as np

In [3]: np.full(10, -1, dtype="u1")
Out[3]: array([255, 255, 255, 255, 255, 255, 255, 255, 255, 255], dtype=uint8)

In [4]: np.full_like(np.ones(10, dtype="u1"), -1, dtype="u1")
Out[4]: array([255, 255, 255, 255, 255, 255, 255, 255, 255, 255], dtype=uint8)

In [5]: np.arange(-5, 0, 1, dtype="u1")
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
Cell In[5], line 1
----> 1 np.arange(-5, 0, 1, dtype="u1")

OverflowError: Python integer -5 out of bounds for uint8

asarray and arange don't permit it, and this is a (very) malformed workflow, so it seems logical to change.

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