[Numpy-discussion] Documentation for dtypes with named fields

josef.pktd at gmail.com josef.pktd at gmail.com
Tue Mar 16 12:23:48 EDT 2010


On Tue, Mar 16, 2010 at 12:04 PM, Sam Tygier
<Sam.Tygier at hep.manchester.ac.uk> wrote:
> On Tue, Mar 16, 2010 at 11:34 AM, Skipper Seabold <jsseabold at gmail.com> wrote:
>>> so i always get the vales back in the original order. is the by design, or a bug?
>>>
>>
>> I've been bitten by this before too and asked the same question with
>> no response.  I think it's just a limitation of the design of
>> structured arrays.
>
> i had a hunt for the code. and it seems easy to fix.
> its in numpy/core/_internal.py:301
>
> --- numpy/core/_internal.py     2010-03-16 16:01:28.000000000 +0000
> +++ numpy/core/_internal.py.old 2010-03-16 16:00:52.000000000 +0000
> @@ -298,7 +298,7 @@
>  def _index_fields(ary, fields):
>     from multiarray import empty, dtype
>     dt = ary.dtype
> -    new_dtype = [(name, dt[name]) for name in fields if name in dt.names]
> +    new_dtype = [(name, dt[name]) for name in dt.names if name in fields]
>     if ary.flags.f_contiguous:
>         order = 'F'
>     else:

You can file a ticket, but if this is a function that is already in
real use, then it would be an unpleasant break in the API

Josef


> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list