diff options
author | Sebastian Berg <sebastianb@nvidia.com> | 2023-05-10 15:11:38 +0200 |
---|---|---|
committer | Sebastian Berg <sebastianb@nvidia.com> | 2023-05-15 12:43:30 +0200 |
commit | 21602a8b1673a7b468d032ef19c20c53ac15c0b9 (patch) | |
tree | 542eddc432d5a6004c9bbc34a119e4bf58163b34 /numpy/core/tests/test_nep50_promotions.py | |
parent | b8a43cb809edd754044af4aadfb9295915333b98 (diff) | |
download | numpy-21602a8b1673a7b468d032ef19c20c53ac15c0b9.tar.gz |
BUG: Fix weak scalar logic for large ints in ufuncs
This fixes it, breaks warnings (partially), but most or all of
those paths should be errors anyway.
Diffstat (limited to 'numpy/core/tests/test_nep50_promotions.py')
-rw-r--r-- | numpy/core/tests/test_nep50_promotions.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/numpy/core/tests/test_nep50_promotions.py b/numpy/core/tests/test_nep50_promotions.py index 9e84c78c1..0b297e0f7 100644 --- a/numpy/core/tests/test_nep50_promotions.py +++ b/numpy/core/tests/test_nep50_promotions.py @@ -181,6 +181,7 @@ def test_nep50_integer_regression(): assert (arr + 2**63).dtype == np.float64 assert (arr[()] + 2**63).dtype == np.float64 + def test_nep50_with_axisconcatenator(): # I promised that this will be an error in the future in the 1.25 # release notes; test this (NEP 50 opt-in makes the deprecation an error). @@ -188,3 +189,34 @@ def test_nep50_with_axisconcatenator(): with pytest.raises(OverflowError): np.r_[np.arange(5, dtype=np.int8), 255] + + +@pytest.mark.parametrize("ufunc", [np.add, np.power]) +@pytest.mark.parametrize("state", ["weak", "weak_and_warn"]) +def test_nep50_huge_integers(ufunc, state): + # Very large integers are complicated, because they go to uint64 or + # object dtype. When mixed with another uint64 that should + np._set_promotion_state(state) + + with pytest.raises(OverflowError): + ufunc(np.int64(0), 2**63) # 2**63 too large for int64 + + if state == "weak_and_warn": + with pytest.warns(UserWarning, + match="result dtype changed.*float64.*uint64"): + with pytest.raises(OverflowError): + ufunc(np.uint64(0), 2**64) + else: + with pytest.raises(OverflowError): + ufunc(np.uint64(0), 2**64) # 2**64 cannot be represented by uint64 + + # However, 2**63 can be represented by the uint64 (and that is used): + if state == "weak_and_warn": + with pytest.warns(UserWarning, + match="result dtype changed.*float64.*uint64"): + res = ufunc(np.uint64(1), 2**63) + else: + res = ufunc(np.uint64(1), 2**63) + + assert res.dtype == np.uint64 + assert res == ufunc(1, 2**63, dtype=object) |