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

Skip to content

error when making view of a recarray of an aligned record dtype #6459

@sklam

Description

@sklam

A TypeError: view would access data parent array doesn't own is raised when a view is created from a recarray and its dtype is an aligned record. The following code demonstrate this error on py3.4 numpy1.10:

import numpy as np

fields = [('a', np.float32), ('b', np.int8)]
nonaligned_dtype = np.dtype(fields)
print(nonaligned_dtype, nonaligned_dtype.type)

aligned_dtype = np.dtype(fields, align=True)
print(aligned_dtype, aligned_dtype.type)

nonaligned_array = np.recarray(1, dtype=nonaligned_dtype)
aligned_array = np.recarray(1, dtype=aligned_dtype)

print(nonaligned_array.dtype)
print(aligned_array.dtype)

print(nonaligned_array[:])  # nonaligned record works
print(aligned_array[:])  # <--- raises view would access data parent array doesn't own

The cause of the error is likely due to the loss of the aligned attribute at

return obj.view(dtype=(self.dtype.type, obj.dtype.fields))
. The itemsize of the aligned_dtype is 8 while the nonaligned_dtype has itemsize 5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions