You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot use negative distance in spherical representation despite error message #11104
>>> from astropy.coordinates import SphericalRepresentation
>>> from astropy import units as u
>>> SphericalRepresentation(10 * u.deg, 45 * u.deg, 10 * u.m)
<SphericalRepresentation (lon, lat, distance) in (deg, deg, m)
(10., 45., 10.)>
>>> SphericalRepresentation(10 * u.deg, 45 * u.deg, -10 * u.m)
Traceback (most recent call last):
File "/home/juanlu/Personal/Astropy/astropy/astropy/coordinates/representation.py", line 1840, in __init__
self._distance = Distance(self._distance, copy=False)
File "/home/juanlu/Personal/Astropy/astropy/astropy/coordinates/distances.py", line 187, in __new__
raise ValueError("Distance must be >= 0. Use the argument "
ValueError: Distance must be >= 0. Use the argument 'allow_negative=True' to allow negative values.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/juanlu/Personal/Astropy/astropy/astropy/coordinates/representation.py", line 1843, in __init__
raise ValueError("Distance must be >= 0. To allow negative "
ValueError: Distance must be >= 0. To allow negative distance values, you must explicitly pass in a `Distance` object with the the argument 'allow_negative=True'.
>>> from astropy.coordinates import Distance
>>> SphericalRepresentation(10 * u.deg, 45 * u.deg, Distance(-10 * u.m, allow_negative=True))
Traceback (most recent call last):
File "/home/juanlu/Personal/Astropy/astropy/astropy/coordinates/representation.py", line 1840, in __init__
self._distance = Distance(self._distance, copy=False)
File "/home/juanlu/Personal/Astropy/astropy/astropy/coordinates/distances.py", line 187, in __new__
raise ValueError("Distance must be >= 0. Use the argument "
ValueError: Distance must be >= 0. Use the argument 'allow_negative=True' to allow negative values.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/juanlu/Personal/Astropy/astropy/astropy/coordinates/representation.py", line 1843, in __init__
raise ValueError("Distance must be >= 0. To allow negative "
ValueError: Distance must be >= 0. To allow negative distance values, you must explicitly pass in a `Distance` object with the the argument 'allow_negative=True'.
I actually wonder if we shouldn't just get rid of the whole check... Why is length special? I can see it for frames or sky coordinates but not for representations. See #11114.
But probably best not to let the perfect stand in the way of the good enough - a direct fix is in #11113.
Activity
WIP: Temporarily remove height validation
mhvk commentedon Dec 1, 2020
I actually wonder if we shouldn't just get rid of the whole check... Why is length special? I can see it for frames or sky coordinates but not for representations. See #11114.
But probably best not to let the perfect stand in the way of the good enough - a direct fix is in #11113.
adrn commentedon Dec 1, 2020
Just a note to say that this looks like a duplicate of #8091?
mhvk commentedon Dec 1, 2020
Indeed, and I see my comments are quite similar to what I'm now suggesting in #11114... I'll note in #11113 that it fixes #8091 as well...
astrojuanlu commentedon Dec 1, 2020
Oops, didn't look for similar issues before opening this one. Closing as duplicate, thanks folks!
WIP: Temporarily remove height validation
WIP: Temporarily remove height validation
WIP: Temporarily remove height validation
WIP: Temporarily remove height validation
WIP: Temporarily remove height validation
WIP: Temporarily remove height validation
WIP: Temporarily remove height validation