Skip to content

viewing an array with a fieldless structured dtype does not update the dtype: #14344

Closed

Description

@ahaldane

As discovered in #14310 , viewing an array with a fieldless structured dtype does not update the dtype/itemsize:

>>> a = np.zeros(2, dtype={'names':[], 'formats':[], 'offsets':[], 'itemsize':8})
>>> b = a.view(np.dtype([]))
>>> b
array([], shape=(2, 0),
      dtype={'names':[], 'formats':[], 'offsets':[], 'itemsize':8})
>>> b.dtype == np.dtype([])
False

Activity

  1. eric-wieser commented on Aug 23, 2019

    @eric-wieser
    Member

    In my opinion, the expected behavior here is to throw an exception, since the new array would need to be 8/0 times longer.

  2. ahaldane commented on Aug 23, 2019

    @ahaldane
    MemberAuthor

    Yeah, I was just thinking about that too.

    Alternatively, we could add a special case for size-0 arrays, which can always be viewed as any dtype. But I'm not sure I like special cases.

    Edit: That is in reference to the case in #14310 where I wanted to view a size-0 array as a fieldless dtype.

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