Skip to content

Commit e236379

Browse files
committed
BUG: Fix cleanup in size 0 put error
Also clean up code a bit, it's confusing to have ifs that can only take one path.
1 parent 8e75175 commit e236379

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

numpy/_core/src/multiarray/item_selection.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0,
397397
if ((ni > 0) && (PyArray_Size((PyObject *)self) == 0)) {
398398
PyErr_SetString(PyExc_IndexError,
399399
"cannot replace elements of an empty array");
400-
return NULL;
400+
goto fail;
401401
}
402402
Py_INCREF(PyArray_DESCR(self));
403403
values = (PyArrayObject *)PyArray_FromAny(values0, PyArray_DESCR(self), 0, 0,
@@ -419,9 +419,8 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0,
419419
Py_INCREF(PyArray_DESCR(self));
420420
obj = (PyArrayObject *)PyArray_FromArray(self,
421421
PyArray_DESCR(self), flags);
422-
if (obj != self) {
423-
copied = 1;
424-
}
422+
copied = 1;
423+
assert(self != obj);
425424
self = obj;
426425
}
427426
max_item = PyArray_SIZE(self);

0 commit comments

Comments
 (0)