Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WarrenWeckesser opened this issue Jun 24, 2020 · 1 comment · Fixed by #20580
Closed

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

WarrenWeckesser opened this issue Jun 24, 2020 · 1 comment · Fixed by #20580

Comments

@WarrenWeckesser
Copy link
Member

WarrenWeckesser commented Jun 24, 2020

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'
@seberg
Copy link
Member

seberg commented Jan 15, 2022

The test here is included as part of gh-20580, so this can be closed when it is merged, I think.

EDIT: (To be clear, I would also be happy to just reject it, but this is the current choice and it does seem very reasonable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants