Skip to content

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

Closed

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.

Activity

  1. ahaldane commented on Oct 12, 2015

    @ahaldane
    Member

    Thanks for the report, it's good to know this problem comes up in the real world.

    Yes, that line should really read

    return obj.view(dtype=(self.dtype.type, obj.dtype))
    

    This is fixed in #6053. If that PR does not get into 1.11, we should have a separate PR with just that fix.

  2. added a commit that references this issue on Oct 18, 2015
    3a816a4
  3. added a commit that references this issue on Oct 18, 2015
    f90fbb9
  4. added a commit that references this issue on Mar 22, 2016
    e5c4cce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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