Description
In #27715 we fixed a bug in nditer internals that affected fancy indexing for StringDType arrays. Ultimately this is caused by NumPy using PyArray_EquivTypes
to check the cast between the DTypes is NPY_NO_CASTING
. That is not a sufficient check in all cases, particularly for user DTypes like StringDType that store some array data on dtype instances. Instead, the correct thing to check is if the cast between the DTypes is NPY_NO_CASTING
and the view_offset
is 0.
We should audit all internal uses of PyArray_EquivTypes
and see if it could be problematic for StringDType arrays. If the check is used to see whether or not a cast between the arrays is needed, it should probably be updated to use PyArray_SafeCast
. We should also investigate whether we should update PyArray_EquivTypes
itself to do this check (or to call PyArray_SafeCast
) and instead replace any places where we want exactly just the check for NPY_NO_CASTING
with a new function that replaces EquivTypes
.