From 5898c2c445cb7fe14e2866b34f625e6f95bbf82f Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Fri, 1 Dec 2006 19:33:05 +0000 Subject: Fix arr.flat[ind] = obj when ind is 1-element and obj is a 1-element sequence. --- numpy/core/src/arrayobject.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'numpy/core/src/arrayobject.c') diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 4b6ae3a6f..0485e5ad3 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -9337,6 +9337,7 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) goto finish; } + if (PySequence_Check(ind) || PySlice_Check(ind)) goto skip; start = PyArray_PyIntAsIntp(ind); if (start==-1 && PyErr_Occurred()) PyErr_Clear(); else { @@ -9350,9 +9351,14 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) PyArray_ITER_GOTO1D(self, start); retval = type->f->setitem(val, self->dataptr, self->ao); PyArray_ITER_RESET(self); + if (retval < 0) { + PyErr_SetString(PyExc_ValueError, + "Error setting single item of array."); + } goto finish; } + skip: Py_INCREF(type); arrval = PyArray_FromAny(val, type, 0, 0, 0, NULL); if (arrval==NULL) return -1; @@ -9408,7 +9414,7 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val) obj = ind; } - if (PyArray_Check(obj)) { + if (obj != NULL && PyArray_Check(obj)) { /* Check for Boolean object */ if (PyArray_TYPE(obj)==PyArray_BOOL) { if (iter_ass_sub_Bool(self, (PyArrayObject *)obj, -- cgit v1.2.1