8000 BUG: view with fieldless dtype should raise if itemsize != 0 · numpy/numpy@847aefc · GitHub
[go: up one dir, main page]

Skip to content

Commit 847aefc

Browse files
committed
BUG: view with fieldless dtype should raise if itemsize != 0
Fixes #14344
1 parent 9cc5f99 commit 847aefc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

numpy/core/include/numpy/ndarraytypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,8 @@ PyArray_CLEARFLAGS(PyArrayObject *arr, int flags)
16951695
#define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num)
16961696
#define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)(obj))->names != NULL)
16971697
#define PyDataType_HASSUBARRAY(dtype) ((dtype)->subarray != NULL)
1698-
#define PyDataType_ISUNSIZED(dtype) ((dtype)->elsize == 0)
1698+
#define PyDataType_ISUNSIZED(dtype) ((dtype)->elsize == 0 && \
1699+
!PyDataType_HASFIELDS(dtype))
16991700
#define PyDataType_MAKEUNSIZED(dtype) ((dtype)->elsize = 0)
17001701

17011702
#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))

numpy/core/tests/test_dtype.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ def test_partial_dict(self):
419419
assert_raises(ValueError, np.dtype,
420420
{'formats': ['i4', 'i4'], 'f0': ('i4', 0), 'f1':('i4', 4)})
421421

422+
def test_fieldless_views(self):
423+
a = np.zeros(2, dtype={'names':[], 'formats':[], 'offsets':[],
424+
'itemsize':8})
425+
assert_raises(ValueError, a.view, np.dtype([]))
426+
422427

423428
class TestSubarray(object):
424429
def test_single_subarray(self):

0 commit comments

Comments
 (0)
0