From 288d07e92327804327815ee915c3f0e5d8eb72ab Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Mon, 11 Dec 2023 17:07:54 -0500 Subject: [PATCH] Apply suggestions from code review [skip-ci] Co-authored-by: Eero Vaher --- astropy/coordinates/distances.py | 2 +- astropy/coordinates/tests/test_distance.py | 11 +++++------ docs/changes/coordinates/15712.bugfix.rst | 5 ++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/astropy/coordinates/distances.py b/astropy/coordinates/distances.py index 7b00db1c8c76..b7957dcd8e92 100644 --- a/astropy/coordinates/distances.py +++ b/astropy/coordinates/distances.py @@ -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()) diff --git a/astropy/coordinates/tests/test_distance.py b/astropy/coordinates/tests/test_distance.py index b4593c204549..988f8b5c6fba 100644 --- a/astropy/coordinates/tests/test_distance.py +++ b/astropy/coordinates/tests/test_distance.py @@ -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 diff --git a/docs/changes/coordinates/15712.bugfix.rst b/docs/changes/coordinates/15712.bugfix.rst index 841b9e1be7a2..fd62441a883f 100644 --- a/docs/changes/coordinates/15712.bugfix.rst +++ b/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.