summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2022-12-13 15:51:05 -0500
committerGitHub <noreply@github.com>2022-12-13 15:51:05 -0500
commitae18b817df2c4411c6a3f180d3e640874cae3a85 (patch)
tree83d8d9bbd7db129061b6e2745f2c736c4f1ddd77
parent3139a881346ff7ad4326ecd296e6eeddf6c268a0 (diff)
parent5df68d2ff0dec50d8b0f55d39e49f83ead13c497 (diff)
downloadnumpy-ae18b817df2c4411c6a3f180d3e640874cae3a85.tar.gz
Merge pull request #22789 from seberg/issue-22787
BUG: Fix infinite recursion in longdouble/large integer scalar ops
-rw-r--r--numpy/core/src/umath/scalarmath.c.src2
-rw-r--r--numpy/core/tests/test_scalarmath.py18
2 files changed, 11 insertions, 9 deletions
diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src
index 70fe963b9..071301036 100644
--- a/numpy/core/src/umath/scalarmath.c.src
+++ b/numpy/core/src/umath/scalarmath.c.src
@@ -1004,7 +1004,7 @@ convert_to_@name@(PyObject *value, @type@ *result, npy_bool *may_need_deferring)
if (overflow) {
/* handle as if "unsafe" */
if (npy_promotion_state != NPY_USE_WEAK_PROMOTION) {
- return PROMOTION_REQUIRED;
+ return OTHER_IS_UNKNOWN_OBJECT;
}
return CONVERT_PYSCALAR;
}
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index 8de821340..13a23ab8a 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -860,27 +860,29 @@ def test_operator_scalars(op, type1, type2):
@pytest.mark.parametrize("op", reasonable_operators_for_scalars)
-def test_longdouble_inf_loop(op):
+@pytest.mark.parametrize("val", [None, 2**64])
+def test_longdouble_inf_loop(op, val):
+ # Note: The 2**64 value will pass once NEP 50 is adopted.
try:
- op(np.longdouble(3), None)
+ op(np.longdouble(3), val)
except TypeError:
pass
try:
- op(None, np.longdouble(3))
+ op(val, np.longdouble(3))
except TypeError:
pass
@pytest.mark.parametrize("op", reasonable_operators_for_scalars)
-def test_clongdouble_inf_loop(op):
- if op in {operator.mod} and False:
- pytest.xfail("The modulo operator is known to be broken")
+@pytest.mark.parametrize("val", [None, 2**64])
+def test_clongdouble_inf_loop(op, val):
+ # Note: The 2**64 value will pass once NEP 50 is adopted.
try:
- op(np.clongdouble(3), None)
+ op(np.clongdouble(3), val)
except TypeError:
pass
try:
- op(None, np.longdouble(3))
+ op(val, np.longdouble(3))
except TypeError:
pass