Skip to content

Commit f2a6b75

Browse files
authored
Merge pull request #29691 from charris/backport-29665
BUG: use correct input dtype in flatiter assignment
2 parents a707cbf + 3d66056 commit f2a6b75

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

numpy/_core/src/multiarray/iterators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
956956
/* We can assume the newly allocated array is aligned */
957957
int is_aligned = IsUintAligned(self->ao);
958958
if (PyArray_GetDTypeTransferFunction(
959-
is_aligned, itemsize, itemsize, type, type, 0,
959+
is_aligned, itemsize, itemsize, PyArray_DESCR(arrval), type, 0,
960960
&cast_info, &transfer_flags) < 0) {
961961
goto finish;
962962
}

numpy/_core/tests/test_stringdtype.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,13 @@ def test_fancy_indexing(string_list):
531531
assert_array_equal(sarr[ind], uarr[ind])
532532

533533

534+
def test_flatiter_indexing():
535+
# see gh-29659
536+
arr = np.array(['hello', 'world'], dtype='T')
537+
arr.flat[:] = 9223372036854775
538+
assert_array_equal(arr, np.array([9223372036854775] * 2, dtype='T'))
539+
540+
534541
def test_creation_functions():
535542
assert_array_equal(np.zeros(3, dtype="T"), ["", "", ""])
536543
assert_array_equal(np.empty(3, dtype="T"), ["", "", ""])

0 commit comments

Comments
 (0)