summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-12-13 18:46:19 +0100
committerSebastian Berg <sebastianb@nvidia.com>2022-12-13 18:55:16 +0100
commit5df68d2ff0dec50d8b0f55d39e49f83ead13c497 (patch)
treeae96326d3dbe9118f61b616516b86f879607ec90 /numpy
parenta24ddad5d1d43ec9bea474abf8068ee6b8db01db (diff)
downloadnumpy-5df68d2ff0dec50d8b0f55d39e49f83ead13c497.tar.gz
BUG: Fix infinite recursion in longdouble/large integer scalar ops
A smal bug snuck in when implementing NEP 50 weak-scalar logic, and unfortunately the tests didn't cover that specific path :/. closes gh-22787
Diffstat (limited to 'numpy')
-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