diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/records.py | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py index 554788253..9f6ba82a0 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -498,7 +498,7 @@ def array(obj, dtype=None, shape=None, offset=0, strides=None, formats=None, elif isinstance(obj, sb.ndarray): if dtype is not None and (obj.dtype != dtype): - obj.dtype = dtype + obj = obj.view(dtype) res = obj.view(recarray) if issubclass(res.dtype.type, nt.void): res.dtype = sb.dtype((record, res.dtype)) diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index f23e28e03..c8872cb21 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -3990,7 +3990,20 @@ _convert_from_commastring(PyObject *obj, int align) listobj = PyObject_CallMethod(_numpy_internal, "_commastring", "O", obj); if (!listobj) return NULL; - res = _convert_from_list(listobj, align, 0); + if (!PyList_Check(listobj) || PyList_GET_SIZE(listobj)<1) { + PyErr_SetString(PyExc_RuntimeError, "_commastring is " \ + "not returning a list with len >= 1"); + return NULL; + } + if (PyList_GET_SIZE(listobj) == 1) { + if (PyArray_DescrConverter(PyList_GET_ITEM(listobj, 0), + &res) == NPY_FAIL) { + res = NULL; + } + } + else { + res = _convert_from_list(listobj, align, 0); + } Py_DECREF(listobj); if (!res && !PyErr_Occurred()) { PyErr_SetString(PyExc_ValueError, "invalid data-type"); |