Skip to content

Commit b7f6de9

Browse files
committed
MNT: Only assert if finalize_descr isn't defined
1 parent ae4be90 commit b7f6de9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

numpy/_core/src/multiarray/convert_datatype.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,18 @@ _get_cast_safety_from_castingimpl(PyArrayMethodObject *castingimpl,
465465
/*
466466
* Check for less harmful non-standard returns. The following two returns
467467
* should never happen:
468-
* 1. No-casting must imply a view offset of 0.
469-
* (with an exception for stringdtype)
468+
* 1. No-casting must imply a view offset of 0 unless the DType
469+
defines a finalization function, which implies it stores data
470+
on the descriptor
470471
* 2. Equivalent-casting + 0 view offset is (usually) the definition
471472
* of a "no" cast. However, changing the order of fields can also
472473
* create descriptors that are not equivalent but views.
473474
* Note that unsafe casts can have a view offset. For example, in
474475
* principle, casting `<i8` to `<i4` is a cast with 0 offset.
475476
*/
476-
if (*view_offset != 0) {
477-
if (from->kind != 'T' || to->kind != 'T') {
478-
assert(casting != NPY_NO_CASTING);
479-
}
477+
if ((*view_offset != 0 &&
478+
NPY_DT_SLOTS(NPY_DTYPE(from))->finalize_descr == NULL)) {
479+
assert(casting != NPY_NO_CASTING);
480480
}
481481
else {
482482
assert(casting != NPY_EQUIV_CASTING

0 commit comments

Comments
 (0)