Skip to content

BUG: lib: Incorrect result from loadtxt with a complicated dtype #16678

Closed
@WarrenWeckesser

Description

@WarrenWeckesser

Here's an example where loadtxt doesn't return the correct data.

In [23]: from io import StringIO

In [24]: import numpy as np

In [25]: point = np.dtype([('x', float), ('y', float)])

In [26]: dt = np.dtype([('code', int), ('points', point, (2,))])

In [27]: dt
Out[27]: dtype([('code', '<i8'), ('points', [('x', '<f8'), ('y', '<f8')], (2,))])

In [28]: np.loadtxt(StringIO('100 1 2 3 4\n200 5 6 7 8\n'), dtype=dt)                                                     
Out[28]: 
array([(100, [(1., 1.), (2., 2.)]), (200, [(5., 5.), (6., 6.)])],
      dtype=[('code', '<i8'), ('points', [('x', '<f8'), ('y', '<f8')], (2,))])

The expected value is array([(100, [(1., 2.), (3., 4.)]), (200, [(5., 6.), (7., 8.)])], ...)

NumPy version:

In [29]: np.__version__                                                                                                   
Out[29]: '1.20.0.dev0+7af1024'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions