From 7f5db09342dadd707c2992842289f894fcc94dab Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Tue, 16 Jan 2024 12:20:57 +0100 Subject: [PATCH] explicitly implement the `dtype` on `numpy` quantities --- pint/facets/numpy/quantity.py | 4 ++++ pint/testsuite/test_numpy.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/pint/facets/numpy/quantity.py b/pint/facets/numpy/quantity.py index 08d7adf9f..deaf675da 100644 --- a/pint/facets/numpy/quantity.py +++ b/pint/facets/numpy/quantity.py @@ -175,6 +175,10 @@ def flat(self): def shape(self) -> Shape: return self._magnitude.shape + @property + def dtype(self): + return self._magnitude.dtype + @shape.setter def shape(self, value): self._magnitude.shape = value diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py index 83308b2f7..15e56358a 100644 --- a/pint/testsuite/test_numpy.py +++ b/pint/testsuite/test_numpy.py @@ -1016,6 +1016,11 @@ def test_shape(self): u.shape = 4, 3 assert u.magnitude.shape == (4, 3) + def test_dtype(self): + u = self.Q_(np.arange(12, dtype="uint32")) + + assert u.dtype == "uint32" + @helpers.requires_array_function_protocol() def test_shape_numpy_func(self): assert np.shape(self.q) == (2, 2)