Skip to content

When accessing multiple fields of a structured array, existence is not checked and return dtype may be empty #5632

Closed
@gerritholl

Description

@gerritholl

When accessing multiple fields of a structured array, numpy fails to verify that all the fields exist. Instead, it will only return existing fields. If none exist, it return a strange object that has a dtype that is empty. Normally, creating an object with an empty dtype is not supposed to be possible (zeros(shape=(5,), dtype=[]) results as expected in TypeError: Empty data-type), so this might actually be a dual bug.

In [216]: A = numpy.empty(dtype=[("A", "f4"), ("B", "f8")], shape=(5,))

In [217]: A[["AA"]]
Out[217]: 
array([(), (), (), (), ()], 
      dtype='{'names':[], 'formats':[], 'offsets':[], 'itemsize':12}')

In [232]: A[["AA", "B"]]
Out[232]: 
array([(0.0,), (0.0,), (0.0,), (0.0,), (0.0,)], 
      dtype=[('B', '<f8')])

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