summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2023-05-15 17:11:06 +0200
committerSebastian Berg <sebastianb@nvidia.com>2023-05-15 17:11:06 +0200
commit626d32fc47a9803e706168ea2d72d3584a4696bd (patch)
tree6f67dfb195eaac7bfdd197a7c1b2d2623a9eca9b
parent21602a8b1673a7b468d032ef19c20c53ac15c0b9 (diff)
downloadnumpy-626d32fc47a9803e706168ea2d72d3584a4696bd.tar.gz
MAINT: Address Marten's review
-rw-r--r--numpy/core/src/multiarray/arrayobject.h8
-rw-r--r--numpy/core/tests/test_nep50_promotions.py14
2 files changed, 17 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.h b/numpy/core/src/multiarray/arrayobject.h
index d9900439c..55ec92463 100644
--- a/numpy/core/src/multiarray/arrayobject.h
+++ b/numpy/core/src/multiarray/arrayobject.h
@@ -41,10 +41,10 @@ static const int NPY_ARRAY_WAS_PYTHON_INT = (1 << 30);
static const int NPY_ARRAY_WAS_PYTHON_FLOAT = (1 << 29);
static const int NPY_ARRAY_WAS_PYTHON_COMPLEX = (1 << 28);
/*
- * Mark that this was a huge int and the array needed replace (no re-use).
- * This flag is only used in the ufunc machinery where it is tricky to cover
- * correct all type resolution paths where `np.array(large_integer)` returns
- * an object array.
+ * Mark that this was a huge int which was turned into an object array (or
+ * unsigned/non-default integer array), but then replaced by a temporary
+ * array for further processing. This flag is only in the ufunc machinery
+ * where it is tricky to cover correctly all type resolution paths.
*/
static const int NPY_ARRAY_WAS_INT_AND_REPLACED = (1 << 27);
static const int NPY_ARRAY_WAS_PYTHON_LITERAL = (1 << 30 | 1 << 29 | 1 << 28);
diff --git a/numpy/core/tests/test_nep50_promotions.py b/numpy/core/tests/test_nep50_promotions.py
index 0b297e0f7..7d52c5089 100644
--- a/numpy/core/tests/test_nep50_promotions.py
+++ b/numpy/core/tests/test_nep50_promotions.py
@@ -195,7 +195,8 @@ def test_nep50_with_axisconcatenator():
@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
+ # object dtype. This tests covers a few possible paths (some of which
+ # cannot give the NEP 50 warnings).
np._set_promotion_state(state)
with pytest.raises(OverflowError):
@@ -220,3 +221,14 @@ def test_nep50_huge_integers(ufunc, state):
assert res.dtype == np.uint64
assert res == ufunc(1, 2**63, dtype=object)
+
+ # The following paths fail to warn correctly about the change:
+ with pytest.raises(OverflowError):
+ ufunc(np.int64(1), 2**63) # np.array(2**63) would go to uint
+
+ with pytest.raises(OverflowError):
+ ufunc(np.int64(1), 2**100) # np.array(2**100) would go to object
+
+ # This would go to object and thus a Python float, not a NumPy one:
+ res = ufunc(1.0, 2**100)
+ assert isinstance(res, np.float64)