Skip to content

Commit

Permalink
TST: Add deprecation tests for out-of-bound pyint conversion deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
seberg committed Oct 5, 2022
1 parent eec99b4 commit df872b4
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions numpy/core/tests/test_deprecations.py
Expand Up @@ -1196,3 +1196,37 @@ def test_deprecated_raised(self, dtype):
np.loadtxt(["10.5"], dtype=dtype)
except ValueError as e:
assert isinstance(e.__cause__, DeprecationWarning)


class TestPyIntConversion(_DeprecationTestCase):
message = r".*stop allowing conversion of out-of-bound.*"

@pytest.mark.parametrize("dtype", np.typecodes["AllInteger"])
def test_deprecated_scalar(self, dtype):
dtype = np.dtype(dtype)
info = np.iinfo(dtype)

# Cover the most common creation paths (all end up in the
# same place):

def scalar(value, dtype):
dtype.type(value)

def assign(value, dtype):
arr = np.array([0, 0, 0], dtype=dtype)
arr[2] = value

def create(value, dtype):
np.array([value], dtype=dtype)


for creation_func in [scalar, assign, create]:
try:
self.assert_deprecated(lambda: creation_func(info.min - 1, dtype))
except OverflowError:
pass # OverflowErrors always happened also before and are OK.

try:
self.assert_deprecated(lambda: creation_func(info.max + 1, dtype))
except OverflowError:
pass # OverflowErrors always happened also before and are OK.

0 comments on commit df872b4

Please sign in to comment.