question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add tests and fix bugs in tabledump and tableload

See original GitHub issue

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 😉 )

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
bsipoczcommented, Dec 21, 2017

I really should not touch fits…

1reaction
bsipoczcommented, Apr 19, 2019

@sbrice - still looks unfixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why a bug fix should "always" include new tests - Matt Lacey
By adding or changing code without adding tests, we risk making future changes harder/slower. Going back to the bug you fixed.
Read more >
Finding and fixing bugs in your tests with fast-check
A follow-up to our JavaScript guide that solves a testing bug with property-based testing ... So you add another test case to address...
Read more >
Bug Fix via TDD - Software & Solution Architecture Consulting
TDD (Test Driven Development) is a next advancement on top of writing unit tests. Firstly, you need unit tests for defects to ensure...
Read more >
issue tracking - Add a unit test for each new bug
In my job all developers that resolve a bug have to add a new unit test that warns about this type of bugs...
Read more >
Good practices: First write the test then fix the bug - le0nidas
Finish the task at hand and then add a test for each case you want to explore. You might end up solving more...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found