Skip to content

ENH: Add commented_names parameter to genfromtxt #31984

Open
Aniketsy wants to merge 4 commits into
numpy:mainfrom
Aniketsy:second-oldest
Open

ENH: Add commented_names parameter to genfromtxt #31984
Aniketsy wants to merge 4 commits into
numpy:mainfrom
Aniketsy:second-oldest

Conversation

@Aniketsy

Copy link
Copy Markdown
Contributor

Fixes #389

PR summary

  • i followed @WarrenWeckesser suggestion

  • added a new commented_names option to genfromtxt so we can control exactly where it look for column names, instead of guessing based on comments.

  • set commented_names=True to grab the names from the last comment line before the data starts or commented_names=False to skip all comments

  • left the default behaviour commented_names=None unchanged

  • As its quite old issue (2012) , excited to move forward with this 😀

First time committer introduction

AI Disclosure

  • yes i've used for generating test and some improvement were suggested

So lets call this work done by Semi-human

@Aniketsy

Copy link
Copy Markdown
Contributor Author

ahh, i think this needs stub update as well, (moving in draft for now) , needs to update docstring too

@Aniketsy
Aniketsy marked this pull request as draft July 13, 2026 13:23
@Aniketsy
Aniketsy marked this pull request as ready for review July 14, 2026 13:39
@ngoldbaum

Copy link
Copy Markdown
Member

Note that new features and expanding the NumPy API surface requires checking in with the numpy-discussion mailing list:

https://numpy.org/devdocs/dev/index.html#guidelines

@ngoldbaum ngoldbaum added 01 - Enhancement 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes labels Jul 16, 2026
@ngoldbaum

Copy link
Copy Markdown
Member

You also need to add docs and a release note for this to be mergeable.

@Aniketsy

Copy link
Copy Markdown
Contributor Author

You also need to add docs and a release note for this to be mergeable.

ah yes, i had in mind for release note, but i was aiming to add in last after review 😀

I'll update with the docs and release note . Thanks :)

@Aniketsy

Copy link
Copy Markdown
Contributor Author

Note that new features and expanding the NumPy API surface requires checking in with the numpy-discussion mailing list:

sorry i didn't get this you mean discussing the new feature in the mailing list.

Reason, i avoided mentioning anywhere, i thought you're busy with conferences i guess, and also there are lot PRs , so it may take sometime to get review. so its better to wait 😊 .

Comment thread numpy/lib/_npyio_impl.py
Comment on lines +1947 to +1955
Reading names from a comment line

>>> s = StringIO('''# a b c
... 1 2 3
... 4 5 6''')
>>> np.genfromtxt(s, names=True, commented_names=True,
... dtype=None, encoding=None).dtype.names
('a', 'b', 'c')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have strong thoughts on this if we need.

Either way is fine i think, we can keep or remove, happy to know thoughts

@Aniketsy

Copy link
Copy Markdown
Contributor Author

@ngoldbaum gentle ping, i've updated with release note and with some improvement. please review these when you get chance . Thanks ;)

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

Labels

01 - Enhancement 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenFromText should be able to read field names from first uncommented line

2 participants