Skip to content

Commit

Permalink
Merge pull request astropy#17358 from neutrinoceros/coordinates/bug/1…
Browse files Browse the repository at this point in the history
…7357/init_angle_from_pandas

BUG: fix instanciating Angle from a pandas Series
  • Loading branch information
mhvk authored Nov 9, 2024
2 parents 59f1ada + d9710d6 commit cb10c98
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion astropy/coordinates/angles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def __new__(cls, angle, unit=None, dtype=np.inexact, copy=True, **kwargs):
if angle.dtype.kind in "SUVO":
angle = [cls(x, unit, copy=COPY_IF_NEEDED) for x in angle]

elif hasattr(angle, "__array__"):
elif hasattr(angle, "__array__") and (
not hasattr(angle, "dtype") or angle.dtype.kind not in "SUVO"
):
angle = np.asarray(angle)

elif isiterable(angle):
Expand Down
11 changes: 11 additions & 0 deletions astropy/coordinates/tests/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ def test_angle_from_pyarrow():
npt.assert_array_equal(angle.value, input_data)


def test_angle_from_pandas():
# see https://github.com/astropy/astropy/issues/17357
pd = pytest.importorskip("pandas")

input_data = ["10 0 0", "12 0 0"]
df = pd.DataFrame({"angle": input_data})
angle = Angle(df["angle"], unit=u.hourangle)
expected = Angle(input_data, u.hourangle)
npt.assert_array_equal(angle.value, expected.value)


def test_dms():
a1 = Angle([0, 45.5, -45.5], unit=u.degree)
d, m, s = a1.dms
Expand Down
1 change: 1 addition & 0 deletions docs/changes/coordinates/17358.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed instantiating ``Angle`` from a ``pandas`` ``Series`` object.

0 comments on commit cb10c98

Please sign in to comment.