From 01d22f0d2fa6fd62c130bffd7762012f4a3381bb Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Wed, 24 May 2023 13:32:37 +0200 Subject: [PATCH] Ensure np.linalg overrides continue to work with numpy >= 1.25 In numpy >=1.25, some functions return namedtuple, which is nice but sadly needs special treatment. --- astropy/units/quantity.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/astropy/units/quantity.py b/astropy/units/quantity.py index febf507b76a..f58aefe56e6 100644 --- a/astropy/units/quantity.py +++ b/astropy/units/quantity.py @@ -716,7 +716,10 @@ def _result_as_quantity(self, result, unit, out): if isinstance(result, (tuple, list)): if out is None: out = (None,) * len(result) - return result.__class__( + # Some np.linalg functions return namedtuple, which is handy to access + # elements by name, but cannot be directly initialized with an iterator. + result_cls = getattr(result, "_make", result.__class__) + return result_cls( self._result_as_quantity(result_, unit_, out_) for (result_, unit_, out_) in zip(result, unit, out) )