Repository navigation
Closed
Labels
Description
The test suite for ccdproc reports a lot of errors in the fits.HDUList.index_of method. I guess that's related to #5065. The test log can be viewed here but they all look similar to this:
tmpdir = local('/tmp/pytest-of-travis/pytest-0/test_initialize_from_fits_with2')
def test_initialize_from_fits_with_data_in_different_extension(tmpdir):
fake_img = np.random.random(size=(100, 100))
new_hdul = fits.HDUList()
hdu1 = fits.PrimaryHDU()
hdu2 = fits.ImageHDU(fake_img)
hdus = fits.HDUList([hdu1, hdu2])
filename = tmpdir.join('afile.fits').strpath
hdus.writeto(filename)
> ccd = CCDData.read(filename, unit='adu')
ccdproc/tests/test_ccddata.py:90:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/travis/miniconda/envs/test/lib/python3.5/site-packages/astropy/nddata/mixins/ndio.py:29: in read
return io_registry.read(cls, *args, **kwargs)
/home/travis/miniconda/envs/test/lib/python3.5/site-packages/astropy/io/registry.py:468: in read
data = reader(*args, **kwargs)
ccdproc/ccddata.py:687: in fits_ccddata_reader
if hdu_flags in hdus:
/home/travis/miniconda/envs/test/lib/python3.5/site-packages/astropy/io/fits/hdu/hdulist.py:295: in __contains__
self._try_while_unread_hdus(self.index_of, item)
/home/travis/miniconda/envs/test/lib/python3.5/site-packages/astropy/io/fits/hdu/hdulist.py:1068: in _try_while_unread_hdus
return func(index, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0x7f158be32c50>, <astropy.io.fits.hdu.image.ImageHDU object at 0x7f158be32438>]
key = None
def index_of(self, key):
if _is_int(key):
return key
elif isinstance(key, tuple):
_key, _ver = key
else:
_key = key
_ver = None
if not isinstance(_key, string_types):
raise TypeError(
'%s indices must be integers, extension names as strings, '
'or (extname, version) tuples; got %r' %
> (self.__class__.__name__, _key))
E TypeError: HDUList indices must be integers, extension names as strings, or (extname, version) tuples; got None
/home/travis/miniconda/envs/test/lib/python3.5/site-packages/astropy/io/fits/hdu/hdulist.py:640: TypeError
Activity
MSeifert04 commentedon Dec 10, 2016
In short it seems like
None in HDUListdoesn't work anymore or shouldn't I have used it like this (it worked before)?mwcraig commentedon Dec 10, 2016
It is not clear to me why this worked before. This line of
io.fits.hdu.hdulist,if not isinstance(_key, string_types):did not change in #5065, all that changed was which error was raised.Ah, right, which means that the except at https://github.com/astropy/astropy/blob/master/astropy/io/fits/hdu/hdulist.py#L296 no longer catches the error.
I think the fix is easy -- the type of error raised should go back to KeyError or we should change the
exceptin__contains__to allow both key and type errors.Arguably a
TypeErroris more sensible here (since the key is the wrong type)...if you get to opening a PR to fix before I do, go ahead. It should be milestoned to 1.3.Maintain 1.x behavior of in operator when key is wrong type
embray commentedon Dec 12, 2016
I think it would be fine to just change it back to a
KeyError.Maintain 1.x behavior of in operator when key is wrong type