Skip to content

Conversation

@eteq
Copy link
Member

@eteq eteq commented Jun 3, 2016

While working on #5002 I encountered a curious problem. If you do python setup.py test -P coordinates everything works just fine. But, if you do python setup.py test -P coordinates --args="-k spherical_offsets", you get:

E       AttributeError: 'SkyCoord' object has no attribute '_origin'

astropy/coordinates/sky_coordinate.py:441: AttributeError

Tracking the origin (pun intended) of this problem led to realization of a problem with SkyCoord: the FRAME_ATTR_NAMES_SET() function in sky_coordinate.py is dynamic, meaning it figures out what all the possible frame attributes are when it gets run... But that dynamic list does not get updated on any already-created SkyCoord objects. So if you create a new frame dynamically (e.g., the first time an AstrometricFrame gets created), it gets added to what FRAME_ATTR_NAMES_SET() returns, but the existing SkyCoords do not have one of them. Hence the above error.

This PR addresses the problem pretty straightforwardly by just letting a SkyCoord stuck in this limbo-like state to just pass through frame attributes as None when necessary, thereby effectively "dodging" the problem. This also adds a regression test that should catch any similar problems that might arise in the future.

cc @astrofrog @taldcroft

@eteq
Copy link
Member Author

eteq commented Jun 3, 2016

I've milestoned it and put it in the changelog for 1.2 on the theory that it gets merged in time. Of course that can be moved if review/travis reveals problems - this is rather a corner case and is unlikely to be encountered too often by users (although it might show up occasionally if a user creates a SkyCoord before any astrometric frames have been made).

@eteq eteq changed the title Fix frame attr set delayed Fix SkyCoord when a new frame is created after a SkyCoord has been inited Jun 3, 2016
@eteq eteq changed the title Fix SkyCoord when a new frame is created after a SkyCoord has been inited Fix SkyCoord AttributeError when a new frame is created after a SkyCoord has been inited Jun 3, 2016
@eteq
Copy link
Member Author

eteq commented Jun 3, 2016

And FWIW, this bug has been in since at least 1.0, it has never appeared before because the SkyOffsetFrame is the first time we've generated a new frame on-the-fly rather than having them all get created at import time. So maybe this should get backported to 1.0 ? As I said it's pretty obscure, but there's an outside change someone has seen this and somehow worked around it...

@astrofrog
Copy link
Member

+1 to backporting to 1.0.10

@astrofrog
Copy link
Member

and 👍 to merging!

@astrofrog astrofrog modified the milestones: v1.0.10, v1.2.0 Jun 3, 2016
@astrofrog
Copy link
Member

@eteq - can you move the changelog entry to 1.0.10?

@eteq
Copy link
Member Author

eteq commented Jun 3, 2016

@astrofrog - Done!

@astrofrog astrofrog merged commit ad895b9 into astropy:master Jun 3, 2016
@eteq eteq deleted the fix-frame-attr-set-delayed branch June 6, 2016 22:26
eteq pushed a commit that referenced this pull request Jun 6, 2016
Fix SkyCoord AttributeError when a new frame is created after a SkyCoord has been inited
eteq pushed a commit that referenced this pull request Jun 6, 2016
includes manual merge for 1.0.x

Fix SkyCoord AttributeError when a new frame is created after a SkyCoord has been inited
@eteq
Copy link
Member Author

eteq commented Jun 6, 2016

backported to 1.2.x in ba428ef and 1.0.x in 5d6eb9a

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants