diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-01-15 16:56:31 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2016-01-15 16:56:31 -0700 |
commit | 35790f6912bfaa4a1fc963ed5c5ca08761d5f9c0 (patch) | |
tree | 5d79bd969ba7087c548cf65160598fe792cbf061 | |
parent | 54224f4e88036a8cd02c1306f2c1a5f655e41e3a (diff) | |
parent | ef09a84e10fa3439ea17f8531431ae874df3afa1 (diff) | |
download | numpy-35790f6912bfaa4a1fc963ed5c5ca08761d5f9c0.tar.gz |
Merge pull request #6987 from jakirkham/test_dot_inner_type_failures
TST, MAINT: Make sure exceptions of `inner` and `dot` match for different cases
-rw-r--r-- | doc/release/1.11.0-notes.rst | 14 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 3 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/doc/release/1.11.0-notes.rst b/doc/release/1.11.0-notes.rst index b5d22d770..cd4f83557 100644 --- a/doc/release/1.11.0-notes.rst +++ b/doc/release/1.11.0-notes.rst @@ -59,6 +59,13 @@ to preserve struct layout). These were never used for anything, so it's unlikely that any third-party code is using them either, but we mention it here for completeness. +*np.dot* now raises ``TypeError`` instead of ``ValueError`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This behaviour mimics that of other functions such as ``np.inner``. If the two +arguments cannot be cast to a common type, it could have raised a ``TypeError`` +or ``ValueError`` depending on their order. Now, ``np.dot`` will now always +raise a ``TypeError``. + New Features ============ @@ -174,6 +181,13 @@ This behaviour mimics that of other functions such as ``np.diagonal`` and ensures, e.g., that for masked arrays ``np.trace(ma)`` and ``ma.trace()`` give the same result. +*np.dot* now raises ``TypeError`` instead of ``ValueError`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This behaviour mimics that of other functions such as ``np.inner``. If the two +arguments cannot be cast to a common type, it could have raised a ``TypeError`` +or ``ValueError`` depending on their order. Now, ``np.dot`` will now always +raise a ``TypeError``. + Deprecations ============ diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 2c17ebe09..1df3d653d 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -827,6 +827,7 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) typenum = PyArray_ObjectType(op2, typenum); typec = PyArray_DescrFromType(typenum); if (typec == NULL) { + PyErr_SetString(PyExc_TypeError, "Cannot find a common data type."); goto fail; } @@ -912,7 +913,7 @@ PyArray_MatrixProduct2(PyObject *op1, PyObject *op2, PyArrayObject* out) typenum = PyArray_ObjectType(op2, typenum); typec = PyArray_DescrFromType(typenum); if (typec == NULL) { - PyErr_SetString(PyExc_ValueError, "Cannot find a common data type."); + 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 c9e610cbf..26617c1fc 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -2045,7 +2045,7 @@ class TestMethods(TestCase): c = 1. A = np.array((1,1), dtype='i,i') - assert_raises(ValueError, np.dot, c, A) + assert_raises(TypeError, np.dot, c, A) assert_raises(TypeError, np.dot, A, c) def test_diagonal(self): |