New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix how coordinates handles negative or nan parallaxes/distances #7988
Conversation
Hi there @adrn 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. Everything looks good from my point of view! 👍 If there are any issues with this message, please report them here. |
548864a
to
9429a34
Compare
Failures are real! Apparently, in master, you can do: >>> rep = coord.SphericalRepresentation(160*u.deg, 10*u.deg, 10*u.pc)
>>> -rep
<SphericalRepresentation (lon, lat, distance) in (deg, deg, pc)
( 160., 10., -10.)> Because of this change, that no longer works: >>> rep = coord.SphericalRepresentation(160*u.deg, 10*u.deg, 10*u.pc)
>>> -rep
NotImplemented I actually feel like the behavior in this PR is more "correct", in the sense that a negative distance doesn't mean anything, so we might want to either not allow this operation (i.e. raise a |
I think I prefer the "special-casing" option, @adrn. That's actually more consistent with what representations do anyway, right? |
Well, kind of. For any Representation object, it uses |
I think we need to keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor suggestions. They're straightforward enough I'll just implement myself and then merge
"distances even when `allow_negative=True`, " | ||
"because negative parallaxes cannot be transformed " | ||
"into distances. See discussion in this paper: " | ||
"https://arxiv.org/abs/1507.02105", AstropyWarning) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! An actual reference!
astropy/coordinates/distances.py
Outdated
"https://arxiv.org/abs/1507.02105", AstropyWarning) | ||
else: | ||
raise ValueError("Negative parallaxes are not " | ||
"interpretable as distances. If you " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the citation to the paper here too, perhaps?
self._distance = self._distance.view(Distance) | ||
try: | ||
self._distance = Distance(self._distance, copy=False) | ||
except ValueError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be other sources of ValueError
here. Easiest thing to do is just check that the message mentions the distance being >=0...?
This addresses a few issues related to how negative parallaxes / distances are handled in coordinates.
with master:
with this PR:
Fixes #7408