diff options
| -rw-r--r-- | numpy/core/src/multiarray/convert_datatype.c | 6 | ||||
| -rw-r--r-- | numpy/core/tests/test_casting_unittests.py | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c index 19127291a..cd0e21098 100644 --- a/numpy/core/src/multiarray/convert_datatype.c +++ b/numpy/core/src/multiarray/convert_datatype.c @@ -3297,8 +3297,10 @@ void_to_void_resolve_descriptors( casting = NPY_NO_CASTING | _NPY_CAST_IS_VIEW; } } - NPY_CASTING field_casting = PyArray_GetCastSafety( - given_descrs[0]->subarray->base, given_descrs[1]->subarray->base, NULL); + + PyArray_Descr *from_base = (from_sub == NULL) ? given_descrs[0] : from_sub->base; + PyArray_Descr *to_base = (to_sub == NULL) ? given_descrs[1] : to_sub->base; + NPY_CASTING field_casting = PyArray_GetCastSafety(from_base, to_base, NULL); if (field_casting < 0) { return -1; } diff --git a/numpy/core/tests/test_casting_unittests.py b/numpy/core/tests/test_casting_unittests.py index c15de3e88..1c465fea1 100644 --- a/numpy/core/tests/test_casting_unittests.py +++ b/numpy/core/tests/test_casting_unittests.py @@ -649,3 +649,11 @@ class TestCasting: with pytest.raises(TypeError, match="casting from object to the parametric DType"): cast._resolve_descriptors((np.dtype("O"), None)) + + @pytest.mark.parametrize("casting", ["no", "unsafe"]) + def test_void_and_structured_with_subarray(self, casting): + # test case corresponding to gh-19325 + dtype = np.dtype([("foo", "<f4", (3, 2))]) + expected = casting == "unsafe" + assert np.can_cast("V4", dtype, casting=casting) == expected + assert np.can_cast(dtype, "V4", casting=casting) == expected |
