Skip to content

ccdproc failures in fits.HDUList.index_of #5583

Closed

Description

@MSeifert04

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

  1. MSeifert04 commented on Dec 10, 2016

    @MSeifert04
    ContributorAuthor

    In short it seems like None in HDUList doesn't work anymore or shouldn't I have used it like this (it worked before)?

  2. mwcraig commented on Dec 10, 2016

    @mwcraig
    Member

    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 except in __contains__ to allow both key and type errors.

    Arguably a TypeError is 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.

  3. added a commit that references this issue on Dec 11, 2016
    0d4b45d
  4. embray commented on Dec 12, 2016

    @embray
    Member

    I think it would be fine to just change it back to a KeyError.

  5. added a commit that references this issue on May 24, 2017
    006f2c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions