From ed5f841bd3517334a173f8032e08b745d43c8033 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Fri, 23 Nov 2018 09:48:48 -0800 Subject: BUG: don't override original errors when casting inside np.dot() fails This makes things harder to debug. --- numpy/core/src/multiarray/multiarraymodule.c | 5 ++++- numpy/core/tests/test_multiarray.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'numpy') 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) -- cgit v1.2.1