You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Sounds correct to me. There's some chance that someone somewhere is
intentionally indexing with missing fields, and if such a person shows up
we might have to go through a deprecation cycle before making this a hard
error. I'm inclined to ignore this possibility until such a person actually
does show up, though, because if you ask for 3 fields and get 2 then you
are going to have problems in most cases already; this behavior seems
pretty difficult to (mis)use correctly.
Want to have a go at putting together a pull request?
On 5 Nov 2014 23:36, "gerritholl" notifications@github.com wrote:
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")])
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:I think it would be more consistent if an error would be raised in both cases.
The text was updated successfully, but these errors were encountered: