Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d930c88

Browse files
njsmithcertik
authored andcommitted
FIX: remove a spurious check in get_cast_transfer_function
At least, I hope it's spurious. Certainly it's creating a spurious error message, is unexpected by callers (one of whom specifically makes the *opposite* check before calling get_cast_transfer_function), and even if it is a useful check for some reason I can't see, it certainly doesn't belong in this function (which is otherwise just taking care of byte-swapping and alignment issues and doesn't know anything about dtypes). And worst case, we'll have turned an exception into a crash; even if I'm wrong, this shouldn't cause any code to go from working to not working, just from broken to slightly-more-broken. Test and original diagnosis by @cgohlke. Fixes gh-2798.
1 parent 931c1c0 commit d930c88

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

numpy/core/src/multiarray/dtype_transfer.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,14 +1475,6 @@ get_cast_transfer_function(int aligned,
14751475
npy_intp src_itemsize = src_dtype->elsize,
14761476
dst_itemsize = dst_dtype->elsize;
14771477

1478-
if (src_dtype->type_num == dst_dtype->type_num &&
1479-
src_dtype->type_num != NPY_DATETIME &&
1480-
src_dtype->type_num != NPY_TIMEDELTA) {
1481-
PyErr_SetString(PyExc_ValueError,
1482-
"low level cast function is for unequal type numbers");
1483-
return NPY_FAIL;
1484-
}
1485-
14861478
if (get_nbo_cast_transfer_function(aligned,
14871479
src_stride, dst_stride,
14881480
src_dtype, dst_dtype,

numpy/core/tests/test_dtype.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ def test_dtype_str_with_long_in_shape(self):
443443
# Pull request #376
444444
dt = np.dtype('(1L,)i4')
445445

446+
def test_base_dtype_with_object_type(self):
447+
# Issue gh-2798
448+
a = np.array(['a'], dtype="O").astype(("O", [("name", "O")]))
446449

447450
class TestDtypeAttributeDeletion(object):
448451

0 commit comments

Comments
 (0)