Closed
Description
If we have an ndarray
with a structured dtype, and I index it with a single non-existent field, an exception (ValueError
) is raised, as expected. However, if I index it with a list of fields, of which at least one is non-existent, no such exception is raised:
In [402]: A = numpy.empty(shape=(5,), dtype=[("A", "f2"), ("B", "f4"), ("C", "f8")])
In [403]: A["D"] # expect: ValueError
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-403-6027a6da83aa> in <module>()
----> 1 A["D"] # expect: ValueError
ValueError: field named D not found
In [404]: A[["C", "D"]] # expect: ValueError
Out[404]:
array([(3.822678085115078e-297,), (-3.1341142554817164e-294,),
(3.8820982892244793e-265,), (1.9848357676925587e-263,),
(1.2046357989657346e-307,)],
dtype=[('C', '<f8')])
In [405]: A[["D"]] # expect: ValueError
Out[405]:
array([(), (), (), (), ()],
dtype='{'names':[], 'formats':[], 'offsets':[], 'itemsize':14}')
I think it would be more consistent if an error would be raised in both cases.
Metadata
Metadata
Assignees
Labels
No labels