Skip to content
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

Comments not ignored in genfromtxt when names=True #9878

Closed
dfreese opened this issue Oct 17, 2017 · 2 comments
Closed

Comments not ignored in genfromtxt when names=True #9878

dfreese opened this issue Oct 17, 2017 · 2 comments

Comments

@dfreese
Copy link

dfreese commented Oct 17, 2017

The following example runs into an error

import numpy as np
from io import StringIO

s = StringIO(u'''# This comment should be ignored
field_name_0 field_name_1
0 1
2 3''')
data = np.genfromtxt(s, names=True)

The first line, minus the comment delimiter is being taken as the names for the dtype, causing the following error.

ValueError: Some errors were detected !
Line #2 (got 2 columns instead of 5)
Line #3 (got 2 columns instead of 5)
Line #4 (got 2 columns instead of 5)

This seems inconsistent with the fact that the following is fine, and that the documentation for the names and comments fields does not suggest this behavior.

import numpy as np
from io import StringIO

s = StringIO(u'''field_name_0 field_name_1
# This comment should be ignored
0 1
2 3''')
data = np.genfromtxt(s, names=True)

Was this behavior intended? If so I would like to update the documentation on the names field. If not, I'd change the names=True to ignore lines that are entirely comments.

@seberg
Copy link
Member

seberg commented Oct 23, 2017

Sure its intended, names are typically comments, so that you can read it in without names as well.

@dfreese
Copy link
Author

dfreese commented Oct 24, 2017

@seberg thanks for the clarification. I've submitted a pull request that I think would clarify this behavior. Thanks!

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

No branches or pull requests

2 participants