Skip to content

Commit

Permalink
TST: Cover additional NEP 50 scalar paths
Browse files Browse the repository at this point in the history
Especially adding coverage also for the power operator which
does not share its code perfectly.
  • Loading branch information
seberg committed Sep 12, 2022
1 parent ede4ca4 commit 8ac5f3f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions numpy/core/tests/test_nep50_promotions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
is adopted in the main test suite. A few may be moved elsewhere.
"""

import operator

import numpy as np

import pytest


Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 8ac5f3f

Please sign in to comment.