esheldon/fitsio — pull request #13 by dstndstn (2013-12-18 19:24:08+00:00)
Title: add support for 'bool' datatype in binary tables

Hi Erin,

I'm having deja vu about this, but this patch allows fitsio to write boolean columns to binary tables. This test case:

'''
import numpy as np
import fitsio
x = np.zeros(10, bool)
x[5:] = True
fitsio.write('test.fits', [x], names=['x'], clobber=True)
'''

used to fail like:

'''
> python test.py
Removing existing file
Traceback (most recent call last):
File "test.py", line 7, in
fitsio.write('test.fits', [x], names=['x'], clobber=True)
File "/Users/dstn/fitsio/fitsio/fitslib.py", line 227, in write
compress=compress, header=header, **keys)
File "/Users/dstn/fitsio/fitsio/fitslib.py", line 460, in write
table_type=table_type)
File "/Users/dstn/fitsio/fitsio/fitslib.py", line 663, in write_table
header=header)
File "/Users/dstn/fitsio/fitsio/fitslib.py", line 755, in create_table_hdu
names, formats, dims = collection2tabledef(data, names=names, table_type=table_type)
File "/Users/dstn/fitsio/fitsio/fitslib.py", line 3023, in collection2tabledef
_, form, dim = npy2fits(send_dt,table_type=table_type)
File "/Users/dstn/fitsio/fitsio/fitslib.py", line 3119, in npy2fits
name, form, dim = npy_num2fits(d, table_type=table_type)
File "/Users/dstn/fitsio/fitsio/fitslib.py", line 3145, in npy_num2fits
raise ValueError("unsupported type '%s'" % npy_dtype)
ValueError: unsupported type 'b1'
'''

and with this patch it works:

'''
> liststruc test.fits

HDU #1 Array: NAXIS = 0, BITPIX = 16

HDU #2 Binary Table: 1 columns x 10 rows
COL NAME FORMAT
1 x L

> tablist test.fits

x
1 F
2 F
3 F
4 F
5 F
6 T
7 T
8 T
9 T
10 T
'''

cheers,
--dustin