summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@google.com>2018-11-23 09:48:48 -0800
committerStephan Hoyer <shoyer@google.com>2018-11-23 09:48:48 -0800
commited5f841bd3517334a173f8032e08b745d43c8033 (patch)
tree03866e2c8824364eee99ce26169944c979f76842 /numpy
parent1d38e41a2acf67c59a3515af2abecbdbf280dc04 (diff)
downloadnumpy-ed5f841bd3517334a173f8032e08b745d43c8033.tar.gz
BUG: don't override original errors when casting inside np.dot() fails
This makes things harder to debug.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c5
-rw-r--r--numpy/core/tests/test_multiarray.py9
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 9e42c115c..22909ae1a 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -919,7 +919,10 @@ PyArray_MatrixProduct2(PyObject *op1, PyObject *op2, PyArrayObject* out)
typenum = PyArray_ObjectType(op2, typenum);
typec = PyArray_DescrFromType(typenum);
if (typec == NULL) {
- PyErr_SetString(PyExc_TypeError, "Cannot find a common data type.");
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "Cannot find a common data type.");
+ }
return NULL;
}
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index d1b306ef0..68fb6acf7 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -2693,6 +2693,15 @@ class TestMethods(object):
assert_raises(TypeError, np.dot, c, A)
assert_raises(TypeError, np.dot, A, c)
+ def test_dot_casting_fails(self):
+
+ class A(object):
+ def __array__(self, *args, **kwargs):
+ raise NotImplementedError
+
+ # Don't override the error from calling __array__()
+ assert_raises(NotImplementedError, np.dot, A(), A())
+
def test_dot_out_mem_overlap(self):
np.random.seed(1)