Skip to content

Commit e1fd9bc

Browse files
taldcrofteteq
authored andcommitted
Merge pull request #5270 from StuartLittlefair/5209_fix
Fix SkyCoord.__init__ edge case with list of one skycoord
1 parent 1f7cb64 commit e1fd9bc

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎astropy/coordinates/sky_coordinate.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,15 +1326,14 @@ def _parse_coordinate_arg(coords, frame, units, init_kwargs):
13261326
# SkyCoords from the list elements and then combine them.
13271327
scs = [SkyCoord(coord, **init_kwargs) for coord in coords]
13281328

1329-
# now check that they're all self-consistent in their frames and
1330-
# check if they are all UnitSphericalRepresentation internally
1331-
allunitsphrepr = True
1329+
# Check that all frames are equivalent
13321330
for sc in scs[1:]:
13331331
if not sc.is_equivalent_frame(scs[0]):
1334-
raise ValueError("List of inputs don't have equivalent "
1335-
"frames: {0} != {1}".format(sc, scs[0]))
1336-
if allunitsphrepr and not isinstance(sc.data, UnitSphericalRepresentation):
1337-
allunitsphrepr = False
1332+
raise ValueError("List of inputs don't have equivalent "
1333+
"frames: {0} != {1}".format(sc, scs[0]))
1334+
1335+
# Now use the first to determine if they are all UnitSpherical
1336+
allunitsphrepr = isinstance(scs[0].data, UnitSphericalRepresentation)
13381337

13391338
# get the frame attributes from the first one, because from above we
13401339
# know it matches all the others

‎astropy/coordinates/tests/test_regression.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313

1414
from ... import units as u
15-
from .. import AltAz, EarthLocation, SkyCoord, get_sun, ICRS
15+
from .. import AltAz, EarthLocation, SkyCoord, get_sun, ICRS, GCRS
1616
from ...time import Time
1717

1818
from ...tests.helper import pytest, assert_quantity_allclose
@@ -143,3 +143,14 @@ def test_regression_4996():
143143

144144
# this is intentially not allclose - they should be *exactly* the same
145145
assert np.all(suncoo.ra.ravel() == suncoo2.ra.ravel())
146+
147+
148+
def test_regression_5209():
149+
"check that distances are not lost on SkyCoord init"
150+
time = Time('2015-01-01')
151+
# this regression test was written for a later astropy with get_moon, but we
152+
# can just mock it up
153+
#moon = get_moon(time)
154+
moon = GCRS(10*u.deg, 20*u.deg, distance=384000*u.km, obstime=time)
155+
new_coord = SkyCoord([moon])
156+
assert_quantity_allclose(new_coord[0].distance, moon.distance)

0 commit comments

Comments
 (0)