Skip to content

Commit

Permalink
Apply suggestions from code review [skip-ci]
Browse files Browse the repository at this point in the history
Co-authored-by: Eero Vaher <eero.vaher@gmail.com>
  • Loading branch information
taldcroft and eerovaher committed Dec 11, 2023
1 parent 585a15b commit 288d07e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion astropy/coordinates/distances.py
Expand Up @@ -162,7 +162,7 @@ def __new__(
unit = u.pc

elif parallax is not None:
parallax = u.Quantity(parallax, copy=False)
parallax = u.Quantity(parallax, copy=False, subok=True)
if unit is None:
unit = u.pc
value = parallax.to_value(unit, equivalencies=u.parallax())
Expand Down
11 changes: 5 additions & 6 deletions astropy/coordinates/tests/test_distance.py
Expand Up @@ -321,13 +321,12 @@ def test_distance_parallax_angle_like():
Adapted from #15693
"""
parallax = Column([1.0, 2.0, 3.0], unit=u.mas)
d0 = Distance(parallax=parallax)
d1 = Distance(parallax=u.Quantity(parallax))
assert np.all(d0 == d1)
assert quantity_allclose(
Distance(parallax=Column([1.0, 2.0, 4.0], unit=u.mas)),
[1000, 500, 250] * u.pc,
)

class FloatMas(float):
unit = u.mas

d2 = Distance(parallax=FloatMas(1.0))
assert d0[0] == d2
assert Distance(parallax=FloatMas(1.0)) == 1000 * u.pc
5 changes: 2 additions & 3 deletions docs/changes/coordinates/15712.bugfix.rst
@@ -1,3 +1,2 @@
Fix a bug in the coordinates ``Distance`` class to allow initialization with
``parallax`` as any angle-like value. This includes types like ``Column`` which have a
unit but are not ``Quantity`` objects.
``Distance`` now accepts as ``parallax`` any angle-like value.
This includes types like ``Column`` which have a unit but are not ``Quantity`` subclasses.

0 comments on commit 288d07e

Please sign in to comment.