Repository: astropy/astropy

Issue:
`numpy.nanvar()` now raises an error if `out` is specified in version 6.1.5
### Description

Apparently a change in #17239 broke the `out` argument in `np.nanvar`, and now a `AttributeError` is raised.

### Expected behavior

For this function to work the same as 6.1.4 and earlier and support the `out` argument

### How to Reproduce

```python
import numpy as np
import astropy.units as u

a = np.random.uniform(0, 1, size=(16, 16)) * u.mm

out = np.zeros(16) * u.mm

np.nanstd(a, axis=1, out=out)
```

```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-9-807e78ea43b5>](https://localhost:8080/#) in <cell line: 1>()
----> 1 np.nanstd(a, out=out)

3 frames
[/usr/local/lib/python3.10/dist-packages/astropy/units/quantity.py](https://localhost:8080/#) in __array_function__(self, function, types, args, kwargs)
   1863                 return self._not_implemented_or_raise(function, types)
   1864 
-> 1865             result = super().__array_function__(function, types, args, kwargs)
   1866             # Fall through to return section
   1867 

[/usr/local/lib/python3.10/dist-packages/numpy/lib/nanfunctions.py](https://localhost:8080/#) in nanstd(a, axis, dtype, out, ddof, keepdims, where)
   1877 
   1878     """
-> 1879     var = nanvar(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
   1880                  keepdims=keepdims, where=where)
   1881     if isinstance(var, np.ndarray):

[/usr/local/lib/python3.10/dist-packages/astropy/units/quantity.py](https://localhost:8080/#) in __array_function__(self, function, types, args, kwargs)
   1859             function_helper = FUNCTION_HELPERS[function]
   1860             try:
-> 1861                 args, kwargs, unit, out = function_helper(*args, **kwargs)
   1862             except NotImplementedError:
   1863                 return self._not_implemented_or_raise(function, types)

[/usr/local/lib/python3.10/dist-packages/astropy/units/quantity_helper/function_helpers.py](https://localhost:8080/#) in nanvar(a, *args, **kwargs)
    258 @function_helper
    259 def nanvar(a, *args, **kwargs):
--> 260     return (a.view(np.ndarray),) + args, kwargs, a.unit**2, None
    261 
    262 

AttributeError: 'numpy.ndarray' object has no attribute 'unit'
```
Which outputs:

### Versions

```
Linux-6.1.85+-x86_64-with-glibc2.35
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
astropy 6.1.5
Numpy 1.26.4
pyerfa 2.0.1.4
Scipy 1.13.1
Matplotlib 3.8.0
```

PR #17263 created a possible regression with using a pandas Series to initialize an Angle.
### Description

For 6.1.4 and previous this would work:
```
from astropy.coordinates import Angle
from astropy import units
import pandas as pd


df = pd.DataFrame({"angle": ["10 0 0", "12 0 0"]})

angle = Angle(df["angle"], unit=units.hourangle)
```
But with 6.1.5 (presumably due to #17263) this now raises `TypeError: The value must be a valid Python or Numpy numeric type.`

### Expected behavior

We should get an angle that looks like `<Angle [10., 12.] hourangle>`

### How to Reproduce

Conda forge pandas, python 3.11, astropy 6.1.5 (this works with 6.1.4 and previous):

```python
from astropy.coordinates import Angle
from astropy import units
import pandas as pd


df = pd.DataFrame({"angle": ["10 0 0", "12 0 0"]})

angle = Angle(df["angle"], unit=units.hourangle)
```


### Versions

```python
import astropy
try:
    astropy.system_info()
except AttributeError:
    import platform; print(platform.platform())
    import sys; print("Python", sys.version)
    import astropy; print("astropy", astropy.__version__)
    import numpy; print("Numpy", numpy.__version__)
    import erfa; print("pyerfa", erfa.__version__)
    try:
        import scipy
        print("Scipy", scipy.__version__)
    except ImportError:
        print("Scipy not installed")
    try:
        import matplotlib
        print("Matplotlib", matplotlib.__version__)
    except ImportError:
        print("Matplotlib not installed")
```
```
Linux-3.10.0-1160.119.1.el7.x86_64-x86_64-with-glibc2.17
Python 3.11.10 | packaged by conda-forge | (main, Oct 16 2024, 01:27:36) [GCC 13.3.0]
astropy 6.1.5
Numpy 2.1.3
pyerfa 2.0.1.4
Scipy not installed
Matplotlib not installed
```


Discussion:

Patch:
diff --git a/astropy/coordinates/angles/core.py b/astropy/coordinates/angles/core.py
index 10e40e76af..b91543a405 100644
--- a/astropy/coordinates/angles/core.py
+++ b/astropy/coordinates/angles/core.py
@@ -184,7 +184,9 @@ class Angle(SpecificTypeQuantity):
                 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):
diff --git a/docs/changes/coordinates/17358.bugfix.rst b/docs/changes/coordinates/17358.bugfix.rst
new file mode 100644
index 0000000000..6d6076372b
--- /dev/null
+++ b/docs/changes/coordinates/17358.bugfix.rst
@@ -0,0 +1,1 @@
+Fixed instantiating ``Angle`` from a ``pandas`` ``Series`` object.


Test patch:
diff --git a/astropy/coordinates/tests/test_arrays.py b/astropy/coordinates/tests/test_arrays.py
index 102b0a4f41..bbb0570c54 100644
--- a/astropy/coordinates/tests/test_arrays.py
+++ b/astropy/coordinates/tests/test_arrays.py
@@ -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