Skip to content

Fix up lazy loading issues - #5589

Merged
eteq merged 6 commits into
astropy:masterfrom
mwcraig:fix-lazy-load-issues
Dec 13, 2016
Merged

eteq merged 6 commits into
astropy:masterfrom
mwcraig:fix-lazy-load-issues

Conversation

@mwcraig

@mwcraig mwcraig commented Dec 11, 2016 •

Copy link
Copy Markdown
Member

Fix or address these issues which resulted from lazy loading. In each case the goal is to maintain the current (1.x) behavior of io.fits.

@eteq -- I believe I've milestoned this correctly, but please modify if not.

edit: changed text of second todo.

@mwcraig mwcraig added this to the v1.3.0 milestone Dec 11, 2016
@mwcraig mwcraig changed the title [WIP] Fix up lazy loading issues Fix up lazy loading issues Dec 11, 2016
Comment thread astropy/io/fits/hdu/hdulist.py Outdated
# max_idx. Note we do not try to be clever about skipping HDUs
# even though key.step might conceivably allow it.
for i in range(number_loaded, max_idx):
print(i)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging print?

Comment thread astropy/io/fits/hdu/hdulist.py Outdated
# have been loaded before passing the slice on to super.
if isinstance(key, slice):
max_idx = self._positive_index_of(key.stop)
if max_idx == sys.maxsize:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about this if, did this make trouble in some tests?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I was just trying to catch the case when the slice had no upper bound specified. I think I can roll it in to the if below, though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just kidding. Turns out sys.maxsize is the value in python 2.7. In python 3 it is None, so special handling of this case is necessary.

@eteq

eteq commented Dec 12, 2016

Copy link
Copy Markdown
Member

@mwcraig - yep, that's the right milestoning. Will want to get confirmation from @nden on #5585 before merging, but this looks good to me.

@eteq

eteq commented Dec 12, 2016

Copy link
Copy Markdown
Member

And re: #5582, FYI : that's definitely for 2.0 as it would require at least one version of deprecation before changing the behavior.

@embray

embray commented Dec 12, 2016

Copy link
Copy Markdown
Member

I'm not quite sure what you mean by "iteration not working". In the basic case iteration was working, just not iteration over a slice.

Comment thread astropy/io/fits/hdu/hdulist.py Outdated
try:
self._try_while_unread_hdus(self.index_of, item)
except KeyError:
except (KeyError, TypeError):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be fine, instead of changing this, to change index_of back to just raising a KeyError if the type of key is invalid. I'm not entirely sure what motivated me to change that in the first place.

Thanks for fixing this!

@embray

embray commented Dec 12, 2016

Copy link
Copy Markdown
Member

LGTM, thanks @mwcraig

@nden

nden commented Dec 12, 2016

Copy link
Copy Markdown
Contributor

This PR fixes the problem in #5585.

I am trying to understand a different regression problem we see caused by the lazy loading PR and not fixed by this one.
It's buried in a layer of packages I'm not very familiar with so it's not easy for me to identify a simple test example. I need a bit more time to investigate.

@nden

nden commented Dec 12, 2016

Copy link
Copy Markdown
Contributor

The other problem we are seeing is due to hdul[(extname, extver)] returning now a TypeError instead of KeyError as before when (extname, extver) is not a valid tuple. In this case a tuple is a valid type so perhaps changing it back to KeyError is not bad?

https://github.com/mwcraig/astropy/blob/436e9fa866ff44af71cf2d06e043a0861757fe9e/astropy/io/fits/hdu/hdulist.py#L664

@mwcraig

mwcraig commented Dec 12, 2016

Copy link
Copy Markdown
Member Author

@nden - I've changed the TypeError back to a KeyError (thanks for clarifying @embray -- wasn't sure which way to go with that change).

@astrofrog

Copy link
Copy Markdown
Member

@mwcraig - could you include a fix for #5594?

Comment thread astropy/io/fits/hdu/hdulist.py Outdated
if not isinstance(_key, string_types):
raise TypeError(
raise KeyError(
'%s indices must be integers, extension names as strings, '

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpicking, but could you change these strings here and a few other places in the file to use the .format() formatting instead of %

@mwcraig

mwcraig commented Dec 12, 2016

Copy link
Copy Markdown
Member Author

@astrofrog -- will do later today.

@eteq eteq added Affects-dev PRs and issues that do not impact an existing Astropy release no-changelog-entry-needed labels Dec 13, 2016
@eteq
eteq merged commit ab7efa6 into astropy:master Dec 13, 2016
eteq added a commit that referenced this pull request Dec 13, 2016
@eteq

eteq commented Dec 13, 2016

Copy link
Copy Markdown
Member

backported to v1.3.x in 459a15c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release Bug io.fits no-changelog-entry-needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in io.fits due to undefined variable Lazy loading of hdus broke slicing of HDULists ccdproc failures in fits.HDUList.index_of

7 participants