diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2018-09-03 14:12:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-03 14:12:12 -0500 |
| commit | 332da0452a0c428b936899bf0cb60019878cadd0 (patch) | |
| tree | eb2c61b0c0c282c9cae95e8c1e885050dbac41b1 | |
| parent | cdbf35b6f8e8a581568ffb966d58e41954f8c9cd (diff) | |
| parent | af82b54c1f18f811232f40e4c8b1f1ca96ee2966 (diff) | |
| download | numpy-332da0452a0c428b936899bf0cb60019878cadd0.tar.gz | |
Merge pull request #11870 from mattip/unicode-to-typeerror
MAINT: dtype(unicode) should raise TypeError on failure
| -rw-r--r-- | numpy/core/src/multiarray/descriptor.c | 6 | ||||
| -rw-r--r-- | numpy/core/tests/test_dtype.py | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c index 1d44cf8be..834a8282b 100644 --- a/numpy/core/src/multiarray/descriptor.c +++ b/numpy/core/src/multiarray/descriptor.c @@ -1439,6 +1439,12 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) PyObject *obj2; obj2 = PyUnicode_AsASCIIString(obj); if (obj2 == NULL) { + /* Convert the exception into a TypeError */ + PyObject *err = PyErr_Occurred(); + if (PyErr_GivenExceptionMatches(err, PyExc_UnicodeEncodeError)) { + PyErr_SetString(PyExc_TypeError, + "data type not understood"); + } return NPY_FAIL; } retval = PyArray_DescrConverter(obj2, at); diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 31ef9d609..e0205a467 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -729,6 +729,7 @@ def test_dtypes_are_true(): def test_invalid_dtype_string(): # test for gh-10440 assert_raises(TypeError, np.dtype, 'f8,i8,[f8,i8]') + assert_raises(TypeError, np.dtype, u'Fl\xfcgel') class TestFromCTypes(object): |
