[AstroPy] table string length truncated after reading table

Josh Walawender jmwalawender at gmail.com
Thu Aug 15 21:45:08 EDT 2013


Hi all,

I'm having a problem working with astropy.table and astropy.io.ascii and I can't tell if the behavior I'm encountering is a feature or a bug. I'm hoping someone can guide me to a good solution. Here's the situation:

I have code which loops though a series of input data files, does analysis, stores the results in an astropy.table, and writes the table to a text file using astropy.io.ascii. One of the fields in the row is the input filename. As the code loops through the input files, it reads the previous table as output by io.ascii, appends a row to the table object, then overwrites the old file with a new one based on the new table which contains the new row.

The symptom is that the all subsequent times through, the length of all strings written to the file name field are now truncated to whatever length the first file name was.

Here's a quick test case (copied and pasted from iPython) demonstrating the problem:

```
In [1]: import astropy.table as table

In [2]: import astropy.io.ascii as ascii

In [4]: firstTable = table.Table(names=('col1', 'col2'), dtypes=('S50', 'S50'))

In [5]: firstTable.add_row(('abcdefghijk', 'short_string'))

In [6]: firstTable.add_row(('abcdefghijklmnop', 'long_string'))

In [7]: print(firstTable)
      col1           col2
---------------- ------------
     abcdefghijk short_string
abcdefghijklmnop  long_string

In [8]: ascii.write(firstTable, "mytable.txt")

In [9]: secondTable = ascii.read("mytable.txt")

In [10]: print(secondTable)
      col1           col2
---------------- ------------
     abcdefghijk short_string
abcdefghijklmnop  long_string

In [11]: secondTable.add_row(('abcdefghijklmnopqrst', 'longer_string'))

In [12]: print(secondTable)
      col1           col2
---------------- ------------
     abcdefghijk short_string
abcdefghijklmnop  long_string
abcdefghijklmnop longer_strin
```

Any suggestions on how to avoid this behavior?

thanks!
Josh

P.S.  Based on the recent discussion on astropy-dev about where to get help, I've also posted this on astrobabel:
http://www.astrobabel.com/v/discussion/77/astropy-question-table-string-length-truncated-after-reading-table#Item_1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20130815/8f96d3cd/attachment.html>


More information about the AstroPy mailing list