Skip to content

Cannot get a view from a composite array with object data members #3253

@mwtoews

Description

@mwtoews

With NumPy 1.7.1 on Win64 with Python 2.7 I see a new issue that was not a problem on a previous version (e.g., 1.6.2).

Consider a composite data type, where a view is obtained from:

import numpy as np
dat1 = np.zeros(3, [('A', 'i'), ('B', 'f')])
new1 = dat1[['B', 'A']]
print(repr(new1))
# array([(0.0, 0), (0.0, 0), (0.0, 0)], 
#      dtype=[('B', '<f4'), ('A', '<i4')])

cool (note: back in 1.4.1 although a subset could be made, the order was the same as the original).

However, if one of types used in the composite data type is '|O8', I can no longer obtain a view:

dat2 = np.zeros(3, [('A', 'i'), ('B', '|O8')])
new2 = dat2[['B', 'A']]

Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\numpy\core_internal.py", line 296, in _index_fields
view = ary.view(dtype=view_dtype)
TypeError: Cannot change data-type for object array.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions