diff options
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 5 |
2 files changed, 11 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 3c735dd7e..0e69cfc07 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -1489,10 +1489,14 @@ OBJECT_to_@TOTYPE@(void *input, void *output, npy_intp n, for (i = 0; i < n; i++, ip++, op += skip) { if (*ip == NULL) { - @TOTYPE@_setitem(Py_False, op, aop); + if (@TOTYPE@_setitem(Py_False, op, aop) < 0) { + return; + } } else { - @TOTYPE@_setitem(*ip, op, aop); + if (@TOTYPE@_setitem(*ip, op, aop) < 0) { + return; + } } } } diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 8be00dad6..b74216418 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -2405,3 +2405,8 @@ class TestRegression(object): v = str(data[['f1']]) if HAS_REFCOUNT: assert_(base <= sys.getrefcount(s)) + + def test_object_casting_errors(self): + # gh-11993 + arr = np.array(['AAAAA', 18465886.0, 18465886.0], dtype=object) + assert_raises(TypeError, arr.astype, 'c8') |