Skip to content

Commit 2186a2b

Browse files
committed
REV: Revert casting part of the old changes
1 parent 1f355d4 commit 2186a2b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

numpy/core/src/multiarray/array_assign_scalar.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,8 @@ PyArray_AssignRawScalar(PyArrayObject *dst,
210210
}
211211

212212
/* Check the casting rule */
213-
// TODO: This is incorrect, we need the information if the input was a
214-
// Python scalar?! Or rather, we want a "inspect" cast-safety
215-
// so to speak. A special scalar assignment just for this purpose
216-
// _probably_ that should be handled earlier, though!
217-
if (!PyArray_CanCastTypeTo(src_dtype, PyArray_DESCR(dst), casting)) {
213+
if (!can_cast_scalar_to(src_dtype, src_data,
214+
PyArray_DESCR(dst), casting)) {
218215
npy_set_invalid_cast_error(
219216
src_dtype, PyArray_DESCR(dst), casting, NPY_TRUE);
220217
return -1;

numpy/core/src/multiarray/convert_datatype.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ PyArray_ValidType(int type);
4747
NPY_NO_EXPORT int
4848
dtype_kind_to_ordering(char kind);
4949

50+
NPY_NO_EXPORT npy_bool
51+
can_cast_scalar_to(PyArray_Descr *scal_type, char *scal_data,
52+
PyArray_Descr *to, NPY_CASTING casting);
53+
5054
/* Used by PyArray_CanCastArrayTo and in the legacy ufunc type resolution */
5155
NPY_NO_EXPORT npy_bool
5256
can_cast_pyscalar_scalar_to(

0 commit comments

Comments
 (0)