summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Haldane <allan.haldane@gmail.com>2018-09-30 18:58:13 -0400
committerCharles Harris <charlesr.harris@gmail.com>2018-10-16 14:41:03 -0600
commit6c6c10b463ee326fe73270f34d412bb2ce8f2dca (patch)
tree46f42e7bff33f8485e3a9e259c11d391b478c38d
parentab298c2cbd474211c0306f97033135a087b9e0f4 (diff)
downloadnumpy-6c6c10b463ee326fe73270f34d412bb2ce8f2dca.tar.gz
BUG: OBJECT_to_* should check for errors
Fixes #11993
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src8
-rw-r--r--numpy/core/tests/test_regression.py5
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 d622effe6..1055f6adc 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 51fe13f5d..26d79468f 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -2410,3 +2410,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')