astropy: Add tests and fix bugs in tabledump and tableload

Follow-up to #6937. We should test that these functions work (and that tableload can load files saved with tabledump). Currently the cdfile option for tabledump is broken (and this file is needed to use tableload):

In [7]: fits.tabledump('astropy/io/fits/tests/data/tb.fits', 'foo.txt', hfile='hfile.txt', cdfile='cdfile.txt', overwrite=True)
WARNING: Overwriting existing file 'foo.txt'. [astropy.io.fits.hdu.table]
WARNING: Overwriting existing file 'hfile.txt'. [astropy.io.fits.hdu.table]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-0fcce33a4feb> in <module>()
----> 1 fits.tabledump('astropy/io/fits/tests/data/tb.fits', 'foo.txt', hfile='hfile.txt', cdfile='cdfile.txt', overwrite=True)

~/dev/astropy/astropy/utils/decorators.py in wrapper(*args, **kwargs)
    485                         # one with the name of the new argument to the function
    486                         kwargs[new_name[i]] = value
--> 487             return function(*args, **kwargs)
    488 
    489         return wrapper

~/dev/astropy/astropy/io/fits/convenience.py in tabledump(filename, datafile, cdfile, hfile, ext, overwrite)
    894 
    895         # Dump the data from the HDU to the files
--> 896         f[ext].dump(datafile, cdfile, hfile, overwrite)
    897     finally:
    898         if closed:

~/dev/astropy/astropy/utils/decorators.py in wrapper(*args, **kwargs)
    485                         # one with the name of the new argument to the function
    486                         kwargs[new_name[i]] = value
--> 487             return function(*args, **kwargs)
    488 
    489         return wrapper

~/dev/astropy/astropy/io/fits/hdu/table.py in dump(self, datafile, cdfile, hfile, overwrite)
   1106         # Process the column definitions
   1107         if cdfile:
-> 1108             self._dump_coldefs(cdfile)
   1109 
   1110         # Process the header parameters

~/dev/astropy/astropy/io/fits/hdu/table.py in _dump_coldefs(self, fileobj)
   1292             attrs = ['disp', 'unit', 'dim', 'null', 'bscale', 'bzero']
   1293             line += ['{:16s}'.format(value if value else '""')
-> 1294                      for value in (getattr(column, attr) for attr in attrs)]
   1295             fileobj.write(' '.join(line))
   1296             fileobj.write('\n')

~/dev/astropy/astropy/io/fits/hdu/table.py in <listcomp>(.0)
   1292             attrs = ['disp', 'unit', 'dim', 'null', 'bscale', 'bzero']
   1293             line += ['{:16s}'.format(value if value else '""')
-> 1294                      for value in (getattr(column, attr) for attr in attrs)]
   1295             fileobj.write(' '.join(line))
   1296             fileobj.write('\n')

ValueError: Unknown format code 's' for object of type 'int'

(this is another side-effect from aaaa6fb56f - #5432, %s was converting to a string if needed, but {:s} does not do that, cc @bsipocz 😉 )

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I really should not touch fits…

@sbrice - still looks unfixed.