diff options
| author | mattip <matti.picus@gmail.com> | 2018-09-03 18:18:57 +0300 |
|---|---|---|
| committer | mattip <matti.picus@gmail.com> | 2018-09-03 18:18:57 +0300 |
| commit | af82b54c1f18f811232f40e4c8b1f1ca96ee2966 (patch) | |
| tree | b95fb665a63d08f9d0c4968cbbd27917cfe08644 | |
| parent | 70450337f35e0a61d654c65b42f311db74df721f (diff) | |
| download | numpy-af82b54c1f18f811232f40e4c8b1f1ca96ee2966.tar.gz | |
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): |
