[Numpy-discussion] genfromtxt() skips comments

Albert Kottke albert.kottke at gmail.com
Fri May 31 18:24:39 EDT 2013


Now try the same thing with np.recfromcsv().

I get the following (Python 3.3):
>>> import io
>>> b = io.BytesIO(b"!blah\n!blah\n!blah\n!A:B:C\n1:2:3\n4:5:6\n")
>>> np.recfromcsv(b, delimiter=':', comments='!')
...
ValueError: Some errors were detected !
    Line #5 (got 3 columns instead of 1)
    Line #6 (got 3 columns instead of 1)


On Fri, May 31, 2013 at 3:02 PM, Pierre GM <pgmdevlist at gmail.com> wrote:

> On May 31, 2013 at 23:08:18 , Albert Kottke (albert.kottke at gmail.com)
> wrote:
> I noticed that genfromtxt() did not skip comments if the keyword names is
> not True. If names is True, then genfromtxt() would take the first line as
> the names. I am proposing a fix to genfromtxt that skips all of the
> comments in a file, and potentially using the last comment line for names.
> I'm quite surprised, as comments are already skipped in my standard numpy
> version (1.7.0). For example:
> >>> S=StringIO("!blah\n!blah\n!blah\n!A:B:C\n1:2:3\n4:5:6\n")
> >>> np.genfromtxt(S, delimiter=":", comments="!", names=("A","B","C"))
> Works as expected, even when using the default `names=None`.
> Comments are taken care of with the `split_line` function (an instance of
> `_iotools.LineSplitter`).
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130531/29dd2476/attachment.html>


More information about the NumPy-Discussion mailing list