File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +17
-11
lines changed
Original file line number Diff line number Diff line change @@ -2034,6 +2034,7 @@ array_assign_subscript(PyArrayObject *self, PyObject *ind, PyObject *op)
2034
2034
goto fail ;
2035
2035
}
2036
2036
2037
+ int allocated_array = 0 ;
2037
2038
if (tmp_arr == NULL ) {
2038
2039
/* Fill extra op, need to swap first */
2039
2040
tmp_arr = mit -> extra_op ;
@@ -2047,6 +2048,7 @@ array_assign_subscript(PyArrayObject *self, PyObject *ind, PyObject *op)
2047
2048
if (PyArray_CopyObject (tmp_arr , op ) < 0 ) {
2048
2049
goto fail ;
2049
2050
}
2051
+ allocated_array = 1 ;
2050
2052
}
2051
2053
2052
2054
if (PyArray_MapIterCheckIndices (mit ) < 0 ) {
@@ -2090,10 +2092,12 @@ array_assign_subscript(PyArrayObject *self, PyObject *ind, PyObject *op)
2090
2092
/* May need a generic copy function (only for refs and odd sizes) */
2091
2093
NPY_ARRAYMETHOD_FLAGS transfer_flags ;
2092
2094
npy_intp itemsize = PyArray_ITEMSIZE (self );
2093
-
2094
- if (PyArray_GetDTypeTransferFunction (1 ,
2095
- itemsize , itemsize ,
2096
- PyArray_DESCR (self ), PyArray_DESCR (self ),
2095
+ // TODO: the heuristic used here to determine the src_dtype might be subtly wrong
2096
+ // for non-REFCHK user DTypes. See gh-27057 for the prior discussion about this.
2097
+ if (PyArray_GetDTypeTransferFunction (
2098
+ 1 , itemsize , itemsize ,
2099
+ allocated_array ? PyArray_DESCR (mit -> extra_op ) : PyArray_DESCR (self ),
2100
+ PyArray_DESCR (self ),
2097
2101
0 , & cast_info , & transfer_flags ) != NPY_SUCCEED ) {
2098
2102
goto fail ;
2099
2103
}
Original file line number Diff line number Diff line change @@ -495,13 +495,15 @@ def test_fancy_indexing(string_list):
495
495
sarr = np .array (string_list , dtype = "T" )
496
496
assert_array_equal (sarr , sarr [np .arange (sarr .shape [0 ])])
497
497
498
- # see gh-27003
499
- for ind in [[0 , 1 ], ...]:
500
- a = np .array (['a' * 16 , 'b' * 16 ], dtype = "T" )
501
- b = np .array (['d' * 16 , 'e' * 16 ], dtype = "T" )
502
- a [ind ] = b
503
- assert_array_equal (a , b )
504
- assert a [0 ] == 'd' * 16
498
+ # see gh-27003 and gh-27053
499
+ for ind in [[True , True ], [0 , 1 ], ...]:
500
+ for lop in [['a' * 16 , 'b' * 16 ], ['' , '' ]]:
501
+ a = np .array (lop , dtype = "T" )
502
+ rop = ['d' * 16 , 'e' * 16 ]
503
+ for b in [rop , np .array (rop , dtype = "T" )]:
504
+ a [ind ] = b
505
+ assert_array_equal (a , b )
506
+ assert a [0 ] == 'd' * 16
505
507
506
508
507
509
def test_creation_functions ():
You can’t perform that action at this time.
0 commit comments