Skip to content

Ensure realize_frame does not overwrite representation class.#6236

Merged
eteq merged 2 commits intoastropy:masterfrom
mhvk:baseframe-realize_frame-regression
Jun 19, 2017
Merged

Ensure realize_frame does not overwrite representation class.#6236
eteq merged 2 commits intoastropy:masterfrom
mhvk:baseframe-realize_frame-regression

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented Jun 17, 2017

fixes #6208

And also an alternative to #6208 which I think is slightly cleaner.

@mhvk mhvk added Affects-dev PRs and issues that do not impact an existing Astropy release Bug coordinates labels Jun 17, 2017
@mhvk mhvk added this to the v2.0.0 milestone Jun 17, 2017
@mhvk mhvk requested review from Cadair and eteq June 17, 2017 15:09
@astrofrog
Copy link
Member

Did you mean to reference #6208?

@mhvk
Copy link
Contributor Author

mhvk commented Jun 17, 2017

Yes, now updated the top entry so that we close the proper one if this is merged!

@mhvk
Copy link
Contributor Author

mhvk commented Jun 17, 2017

@Cadair - apart from review, I of course mostly hope to hear that this in fact solves the regression!

Copy link
Member

@adrn adrn left a comment

Choose a reason for hiding this comment

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

A few minor questions. Would be good to hear from @Cadair whether this fixes the Sunpy breakage.

from .frame_attributes import FrameAttribute

# Import all FrameAttributes so we don't break backwards-compatibility
# Import all orher FrameAttributes so we don't break backwards-compatibility
Copy link
Member

Choose a reason for hiding this comment

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

Typo: other

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

# (some users rely on them being here, although that is not
# encouraged, as this is not the public API location.)
from .frame_attributes import *
from .frame_attributes import (
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change this back? The argument for * was that we then don't have to remember to update this if we add any more FrameAttribute classes...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was partially to keep my is-something-imported checker happy, but mostly because ideally people do not import the attributes from baseframe. This way, we don't break backwards compatibility, but if we define a new attribute and someone wants to use it, it will break, and they'll realize that they should change...

# Here we pass representation=None to _apply, since we do not want
# to insist that the realized frame has the same representation as
# self. [Avoids breaking sunpy; see gh-6208]
# TODO: expose this? But unhandy change of name, since in the
Copy link
Member

Choose a reason for hiding this comment

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

In #6219 I added representation_cls and am planning to deprecate representation - I guess you could use _representation_cls just to be consistent? I don't really care.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that would be great! It is such a pain as is. So, I changed the name here, but didn't yet expose it, as I'd like to focus on just fixing the regression.

else:
data = self.data if self.has_data else None

representation = kwargs.pop('_repr_cls', self.representation)
Copy link
Member

Choose a reason for hiding this comment

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

See comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

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

This fixes the issue. Thanks a lot.

super(MyFrame, self).__init__(*args, **kwargs)
if not _rep_kwarg:
self.representation = self.default_representation
self._data = self.data.represent_as(self.representation)
Copy link
Member

Choose a reason for hiding this comment

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

So we don't actually call represent_as in the __init__ we just set the representation attribute and set _data equal to the rep we make.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to hear this fixes the problem! Note that this is the BaseRepresentation.represent_as which should be equivalent to the explicit initialization you do in sunpy -- I just wanted to make an example that didn't depend on it.

Copy link
Member

Choose a reason for hiding this comment

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

ah cool ok.

Copy link
Member

@eteq eteq left a comment

Choose a reason for hiding this comment

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

LGTM. Merging!

@eteq eteq merged commit ced8bc2 into astropy:master Jun 19, 2017
mirca pushed a commit to mirca/astropy that referenced this pull request Jun 19, 2017
@mhvk mhvk deleted the baseframe-realize_frame-regression branch August 31, 2017 23:42
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 coordinates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants