Skip to content

Commit 7078203

Browse files
committed
BUG: Fix failed itemsetting in fromiter
Seems we never had a test for this simple path...
1 parent cba4ae7 commit 7078203

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

numpy/core/src/multiarray/ctors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3968,7 +3968,7 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, npy_intp count)
39683968
}
39693969
}
39703970

3971-
if (PyArray_Pack(dtype, item, value) < -1) {
3971+
if (PyArray_Pack(dtype, item, value) < 0) {
39723972
Py_DECREF(value);
39733973
goto done;
39743974
}

numpy/core/tests/test_numeric.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,14 @@ def test_too_few_items(self):
12561256
with pytest.raises(ValueError, match=msg):
12571257
np.fromiter([1, 2, 3], count=10, dtype=int)
12581258

1259+
def test_failed_itemsetting(self):
1260+
with pytest.raises(TypeError):
1261+
np.fromiter([1, None, 3], dtype=int)
1262+
1263+
# The following manages to hit somewhat trickier code paths:
1264+
iterable = ((2, 3, 4) for i in range(5))
1265+
with pytest.raises(ValueError):
1266+
np.fromiter(iterable, dtype=np.dtype((int, 2)))
12591267

12601268
class TestNonzero:
12611269
def test_nonzero_trivial(self):

0 commit comments

Comments
 (0)