diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-09-12 17:07:18 +0200 |
---|---|---|
committer | Sebastian Berg <sebastianb@nvidia.com> | 2022-10-12 10:41:40 +0200 |
commit | 4ecc03549750e733690d057f7a9c06909788a586 (patch) | |
tree | 452a5948488eb0d46a77fc4e80798d6f4eb9c1cb /numpy | |
parent | 0375d16f2fa8b5d8c68ef7ec641613c0a1b80658 (diff) | |
download | numpy-4ecc03549750e733690d057f7a9c06909788a586.tar.gz |
TST: Cover additional NEP 50 scalar paths
Especially adding coverage also for the power operator which
does not share its code perfectly.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_nep50_promotions.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/core/tests/test_nep50_promotions.py b/numpy/core/tests/test_nep50_promotions.py index 220482dcc..4bc034920 100644 --- a/numpy/core/tests/test_nep50_promotions.py +++ b/numpy/core/tests/test_nep50_promotions.py @@ -4,7 +4,10 @@ mode. Most of these test are likely to be simply deleted again once NEP 50 is adopted in the main test suite. A few may be moved elsewhere. """ +import operator + import numpy as np + import pytest @@ -123,6 +126,25 @@ def test_nep50_weak_integers_with_inexact(dtype): assert res == np.inf +@pytest.mark.parametrize("op", [operator.add, operator.pow, operator.eq]) +def test_weak_promotion_scalar_path(op): + # Some additional paths excercising the weak scalars. + np._set_promotion_state("weak") + + # Integer path: + res = op(np.uint8(3), 5) + assert res == op(3, 5) + assert res.dtype == np.uint8 or res.dtype == bool + + with pytest.raises(OverflowError): + op(np.uint8(3), 1000) + + # Float path: + res = op(np.float32(3), 5.) + assert res == op(3., 5.) + assert res.dtype == np.float32 or res.dtype == bool + + def test_nep50_complex_promotion(): np._set_promotion_state("weak") |