-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Closed
Description
Declaring a dtype with the dict 'name','format','offset' format could result in invisible fields. The same dtype however is not reproduced by its own descr that uses the list of tuples format. The invisibility does matter especially at comparisons/sorting. In the following case e.g. B and C should behave the same way:
>>> A
array([(0, 2, 0), (0, 1, 1), (0, 0, 5), (1, 3, 2), (1, 2, 3)],
dtype=[('a', '<i8'), ('b', '<i8'), ('c', '<i8')])
>>> B=A.view(dtype={'names':('A','C'),'formats':(int,int),'offsets':(A.dtype.fields['a'][1],A.dtype.fields['c'][1])})
>>> B
array([(0, 0), (0, 1), (0, 5), (1, 2), (1, 3)],
dtype=[('A', '<i8'), ('', '|V8'), ('C', '<i8')])
>>> B.sort()
>>> B
array([(0, 0), (0, 1), (0, 5), (1, 2), (1, 3)],
dtype=[('A', '<i8'), ('', '|V8'), ('C', '<i8')])
>>> A
array([(0, 2, 0), (0, 1, 1), (0, 0, 5), (1, 3, 2), (1, 2, 3)],
dtype=[('a', '<i8'), ('b', '<i8'), ('c', '<i8')])
>>> C=A.view(dtype=B.dtype.descr)
>>> C
array([(0, <read-write buffer ptr 0x7f9de28bed58, size 8 at 0x10e60f830>, 0),
(0, <read-write buffer ptr 0x7f9de28bed70, size 8 at 0x10e60f830>, 1),
(0, <read-write buffer ptr 0x7f9de28bed88, size 8 at 0x10e60f830>, 5),
(1, <read-write buffer ptr 0x7f9de28beda0, size 8 at 0x10e60f830>, 2),
(1, <read-write buffer ptr 0x7f9de28bedb8, size 8 at 0x10e60f830>, 3)],
dtype=[('A', '<i8'), ('f1', '|V8'), ('C', '<i8')])
>>> C.sort()
>>> A
array([(0, 0, 5), (0, 1, 1), (0, 2, 0), (1, 2, 3), (1, 3, 2)],
dtype=[('a', '<i8'), ('b', '<i8'), ('c', '<i8')])Also, on save and load into .npy file, the invisible field becomes visible.
Reactions are currently unavailable