[AstroPy] reading table from string

Erik Bray embray at stsci.edu
Mon Oct 28 11:55:14 EDT 2013


On 10/24/2013 11:34 PM, Semyeong Oh wrote:
> Hi,
>
> If I use 'names' keyword when reading a table from string,
> the first line is ignored.
>
> new="""
> 3102  0.32 <tel:3102%C2%A0%200.32>      4167  4085   Q1250+568-A
> 877   0.22      4378  3892   "Source 82"
> """
> t = ascii.read(new, names=['obsid','redshift','X','Y','object'])
> print t
>
>
> obsid redshift  X    Y     object
> ----- -------- ---- ---- ---------
>    877     0.22 4378 3892 Source 82
>
>
> Is this a bug?

Hi,

I'm not an expert with asciitables so I'm not sure, but I don't *think* that's a 
bug.  I think that the default reader assumes your first line is a header and 
throws it away.  For example, try:

print ascii.read(new, data_start=0, names=['obsid','redshift','X','Y','object'])

That should work.

That said, I think this is surprising behavior, especially considering that you 
manually provided the column names.  If I run it without providing column names 
it still reads the whole table and uses dummy column names:

In [9]: print ascii.read(dat)
col1 col2 col3 col4     col5
---- ---- ---- ---- -----------
3102 0.32 4167 4085 Q1250+568-A
  877 0.22 4378 3892   Source 82

So maybe this is a bug after all...

Erik



More information about the AstroPy mailing list