diff options
-rw-r--r-- | numpy/core/src/multiarray/convert_datatype.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c index 8cdd65d7b..0d28ead89 100644 --- a/numpy/core/src/multiarray/convert_datatype.c +++ b/numpy/core/src/multiarray/convert_datatype.c @@ -719,7 +719,11 @@ can_cast_scalar_to(PyArray_Descr *scal_type, char *scal_data, /* An aligned memory buffer large enough to hold any type */ npy_longlong value[4]; - if (casting == NPY_UNSAFE_CASTING) { + /* + * If the two dtypes are actually references to the same object + * or if casting type is forced unsafe then always OK. + */ + if (scal_type == to || casting == NPY_UNSAFE_CASTING ) { return 1; } |