taldcroft / asciitable

Extensible ASCII table reader
http://cxc.harvard.edu/contrib/asciitable/
36 stars 9 forks source link

First data line skipped for NoHeader with names supplied, guess=True #19

Open taldcroft opened 13 years ago

taldcroft commented 13 years ago

Something unexpected is happening for a tab-delimited data table with no header line:

>>> import asciitable
>>> asciitable.read("1\t2\n3\t4")
rec.array([(1, 2), (3, 4)], 
      dtype=[('col1', '<i8'), ('col2', '<i8')])

>>> asciitable.read("1\t2\n3\t4", names=['c1', 'c2'])
rec.array([(3, 4)], 
      dtype=[('c1', '<i8'), ('c2', '<i8')])

>>> asciitable.read("1\t2\n3\t4", names=['c1', 'c2'], Reader=asciitable.NoHeader, 
                              delimiter='\t')
rec.array([(1, 2), (3, 4)], 
      dtype=[('c1', '<i8'), ('c2', '<i8')])

>>> asciitable.read("1\t2\n3\t4", names=['c1', 'c2'], Reader=asciitable.NoHeader)
rec.array([(3, 4)], 
      dtype=[('c1', '<i8'), ('c2', '<i8')])

>>> asciitable.read("1 2\n3 4", names=['c1', 'c2'], Reader=asciitable.NoHeader)
rec.array([(1, 2), (3, 4)], 
      dtype=[('c1', '<i8'), ('c2', '<i8')])
taldcroft commented 13 years ago

In 0.7.1, one of the two fail cases above is fixed:

>>> asciitable.read("1\t2\n3\t4", names=['c1', 'c2'])
rec.array([(3, 4)], 
      dtype=[('c1', '<i8'), ('c2', '<i8')])

>>> asciitable.read("1\t2\n3\t4", names=['c1', 'c2'], Reader=asciitable.NoHeader)
rec.array([(1, 2), (3, 4)], 
      dtype=[('c1', '<i8'), ('c2', '<i8')])