Skip to content

Add equality for representations (to fix #8138) - #8205

Closed
eteq wants to merge 9 commits into
astropy:masterfrom
eteq:fix-repr-is-equiv
Closed

eteq wants to merge 9 commits into
astropy:masterfrom
eteq:fix-repr-is-equiv

Conversation

@eteq

@eteq eteq commented Dec 3, 2018

Copy link
Copy Markdown
Member

This fixes #8138 by adding an equality comparison for representation objects. Some implementation notes:

  • It does the reasonable thing of converting to cartesian if the two objects aren't the same
  • It yields False (not TypeError) if the right-hand-side is not a representation
  • It does not try to do fancy differential-converting - it will only return True if the classes of the representation match and the differentials are all equal.

Note that this is high priority as it is currently a blocker for release of 3.1 because it fixes #8138 (somewhat counter-intuitively by creating a new feature

cc @adrn @bsipocz @astrofrog (the latter mostly because it probably needs a 👍 since we're post feature-freeze... although debatable since it's both a new feature and a bug fix?)

@eteq eteq added this to the v3.1 milestone Dec 3, 2018
@eteq
eteq requested a review from adrn December 3, 2018 08:45
@eteq eteq changed the title Fix repr is equiv Add equality for representations (to fix #8138) Dec 3, 2018
@StuartLittlefair

Copy link
Copy Markdown
Contributor

looks good to me @eteq

@mhvk mhvk left a comment

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.

Two comments, which lead to a larger one: I think it is a big mistake to rush this - I feel quite strongly that __eq__ should, like ndarray, return a boolean array, and we need to think much harder about what we do with differentials. I think for now we should just move this logic to is_equivalent_frame, where it is much clearer what we actually want to happen. And then it is a proper bug fix, not the introduction of a new feature.

Comment thread astropy/coordinates/representation.py Outdated

def __eq__(self, other):
if not isinstance(other, BaseRepresentationOrDifferential):
return False

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.

This is wrong: should return NotImplemented (CPython will convert to False).

Comment thread astropy/coordinates/representation.py Outdated
if isinstance(other, self.__class__):
for comp in self.components:
if np.any(getattr(self, comp) != getattr(other, comp)):
return False

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.

Why are we not returning the array here?

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.

Ah, very good point. I had originally been thinking that there's no natural way to do it due to components being ambiguous, but now that you bring it up you're absolutely right that it's just an np.all(...) outside the loop.

@eteq eteq mentioned this pull request Dec 4, 2018
@eteq

eteq commented Dec 4, 2018

Copy link
Copy Markdown
Member Author

I see @mhvk's point here, and created #8218 to fix the immediate problem. If we opt for that route, this should just be re-milestoned 3.2 and we should make a decision on it by then.

@StuartLittlefair

Copy link
Copy Markdown
Contributor

I'm not entirely sure I agree with @mhvk about returning an array but do agree on differentials, and the fact that there's some disagreement definitely argues against haste in implementing this feature. I'd vote for #8218 on that basis.

@mhvk

mhvk commented Dec 4, 2018

Copy link
Copy Markdown
Contributor

Yes, let's postpone this one to 3.2. The reason to like arrays is that I also see representations as a vector-array class, and for arrays the default is to return array of bool. Plus, it is easy to check equality of all for an array, but not easy to get out equality for individual items if they have already been combined. That said, numpy does break python expectations with this, which is a pain.

@adrn

adrn commented Dec 4, 2018

Copy link
Copy Markdown
Member

Yes, I agree with @mhvk!

@bsipocz bsipocz modified the milestones: v3.1, v3.2 Dec 5, 2018
@eteq
eteq force-pushed the fix-repr-is-equiv branch from 6fde114 to 0362e37 Compare April 18, 2019 21:22
@eteq

eteq commented Apr 18, 2019

Copy link
Copy Markdown
Member Author

@StuartLittlefair @mhvk @adrn - well 3.2 freeze is coming close again... I implemented the suggestions @mhvk made on the version from 6 months back and did a rebase.

So the two items to discuss are:

  1. Returning arrays from __eq__. Note that this is an API-breaking change now. And as the failures in the tests will indicate (which I left in for illustrative purposes), they are relatively subtle - of the The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() variety. I think this might affect a significant amount of downstream user code so I am thinking it might be better to take a smaller step of leaving it as "equal or not"... But if there's some intermediate pathway I'm all ears?
  2. Differentials I think are easier if we do the "easy" way I'm suggesting above. That is, we just check their components in the same way.

We could consider doing a "bigger" break (both in the differentials and the representations) in 4.0 perhaps?

@mhvk

mhvk commented Apr 19, 2019

Copy link
Copy Markdown
Contributor

On (1), I think you mean that changing it to returning an array will be an API breaking change if we merge this, right?

I'm still not at all comfortable with checking equality of all elements: in many ways representations can be thought of as structured arrays or tables, and for those too you would expect that comparison would be by row rather than for all.

I'm wondering if we aren't better of to define representation_isclose and representation_allclose functions, a bit like we ended up doing for Quantity.

@adrn

adrn commented Apr 19, 2019

Copy link
Copy Markdown
Member

👍 to the idea of having isclose and allclose functions (and then also added as methods on BaseRepresentation and BaseDifferential)!

@eteq

eteq commented Apr 19, 2019

Copy link
Copy Markdown
Member Author

Gotcha, I like that suggestion too @mhvk. No time to do that now as it would be a pretty major change to this PR, so I'm re-milestoning this to 4.0.

@eteq eteq modified the milestones: v3.2, v4.0 Apr 19, 2019
@eteq

eteq commented Apr 19, 2019

Copy link
Copy Markdown
Member Author

(Note that I'm more than happy for anyone else to take this on though...)

@astropy-bot

astropy-bot Bot commented Sep 21, 2019

Copy link
Copy Markdown

Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in a month if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@astropy-bot

astropy-bot Bot commented Oct 23, 2019

Copy link
Copy Markdown

I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here.

@astropy-bot astropy-bot Bot added the closed-by-bot Closed by stale bot label Oct 23, 2019
@astropy-bot astropy-bot Bot closed this Oct 23, 2019
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.

Determine the root cause of the is_equivalent_frame change and document it

5 participants