diff options
author | Allan Haldane <allan.haldane@gmail.com> | 2018-09-30 18:58:13 -0400 |
---|---|---|
committer | Allan Haldane <allan.haldane@gmail.com> | 2018-09-30 21:13:37 -0400 |
commit | dfa2a8da81704d454660a44018a6a47fa0af2d42 (patch) | |
tree | 7a539e688fdc7e437e9034e2b3f08c8bc5a01dea /numpy | |
parent | cd4fb52e889394125a1bb185b54ff8ca8800c5b1 (diff) | |
download | numpy-dfa2a8da81704d454660a44018a6a47fa0af2d42.tar.gz |
BUG: OBJECT_to_* should check for errors
Fixes #11993
Diffstat (limited to 'numpy')
-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') |