From b745608142ec22fa6f147b9eeb3733712f41d6a9 Mon Sep 17 00:00:00 2001
From: Justus Magin <keewis@posteo.de>
Date: Thu, 30 Jan 2025 15:20:15 +0100
Subject: [PATCH 1/5] check that aggregations result in array objects

---
 xarray/tests/test_namedarray.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xarray/tests/test_namedarray.py b/xarray/tests/test_namedarray.py
index 7bd2c3bec06..5643ed0d37f 100644
--- a/xarray/tests/test_namedarray.py
+++ b/xarray/tests/test_namedarray.py
@@ -591,6 +591,12 @@ def test_warn_on_repeated_dimension_names(self) -> None:
         with pytest.warns(UserWarning, match="Duplicate dimension names"):
             NamedArray(("x", "x"), np.arange(4).reshape(2, 2))
 
+    def test_aggregation(self) -> None:
+        x = NamedArray(("x", "y"), np.arange(4).reshape(2, 2))
+
+        result = x.sum()
+        assert isinstance(result.data, np.ndarray)
+
 
 def test_repr() -> None:
     x: NamedArray[Any, np.dtype[np.uint64]]

From 6d21fda6cfae08583d4c78e0756592a5bbb74492 Mon Sep 17 00:00:00 2001
From: Justus Magin <keewis@posteo.de>
Date: Thu, 30 Jan 2025 15:22:33 +0100
Subject: [PATCH 2/5] don't consider numpy scalars as arrays

---
 xarray/namedarray/core.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xarray/namedarray/core.py b/xarray/namedarray/core.py
index 683a1266472..cdf9eab5c8d 100644
--- a/xarray/namedarray/core.py
+++ b/xarray/namedarray/core.py
@@ -205,7 +205,7 @@ def from_array(
 
         return NamedArray(dims, data, attrs)
 
-    if isinstance(data, _arrayfunction_or_api):
+    if isinstance(data, _arrayfunction_or_api) and not isinstance(data, np.generic):
         return NamedArray(dims, data, attrs)
 
     if isinstance(data, tuple):

From 42043c8580ac5e75986a450e2626fd194a039115 Mon Sep 17 00:00:00 2001
From: Justus Magin <keewis@posteo.de>
Date: Thu, 30 Jan 2025 15:32:32 +0100
Subject: [PATCH 3/5] changelog [skip-ci]

---
 doc/whats-new.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/whats-new.rst b/doc/whats-new.rst
index 76ed4c43882..c76f3800f2b 100644
--- a/doc/whats-new.rst
+++ b/doc/whats-new.rst
@@ -106,6 +106,8 @@ Bug fixes
   By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
 - Fix weighted ``polyfit`` for arrays with more than two dimensions (:issue:`9972`, :pull:`9974`).
   By `Mattia Almansi <https://github.com/malmans2>`_.
+- Cast ``numpy`` scalars to arrays in :py:meth:`NamedArray.from_arrays` (:issue:`10005`, :pull:`10008`)
+  By `Justus Magin <https://github.com/keewis>`_.
 
 Documentation
 ~~~~~~~~~~~~~

From b9643b8127c2ca25d73a620bb5506519286260c7 Mon Sep 17 00:00:00 2001
From: Justus Magin <keewis@posteo.de>
Date: Thu, 30 Jan 2025 15:56:10 +0100
Subject: [PATCH 4/5] retrigger CI


From c0c5c5455d0b3c877d958318ef2e4ea8f05d94be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kai=20M=C3=BChlbauer?= <kmuehlbauer@wradlib.org>
Date: Thu, 30 Jan 2025 16:14:53 +0100
Subject: [PATCH 5/5] Update xarray/tests/test_namedarray.py

---
 xarray/tests/test_namedarray.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xarray/tests/test_namedarray.py b/xarray/tests/test_namedarray.py
index 5643ed0d37f..537cd824767 100644
--- a/xarray/tests/test_namedarray.py
+++ b/xarray/tests/test_namedarray.py
@@ -592,6 +592,7 @@ def test_warn_on_repeated_dimension_names(self) -> None:
             NamedArray(("x", "x"), np.arange(4).reshape(2, 2))
 
     def test_aggregation(self) -> None:
+        x: NamedArray[Any, np.dtype[np.int64]]
         x = NamedArray(("x", "y"), np.arange(4).reshape(2, 2))
 
         result = x.sum()