From 8aece847191339f4b406066d896bccd8af8702f0 Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 6 Jun 2022 13:46:05 +0200 Subject: [PATCH 1/3] change `.pint.magnitude` to return a `DataArray` --- pint_xarray/accessors.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pint_xarray/accessors.py b/pint_xarray/accessors.py index 4ebe3241..ee772673 100644 --- a/pint_xarray/accessors.py +++ b/pint_xarray/accessors.py @@ -435,8 +435,7 @@ def dequantify(self, format=None): @property def magnitude(self): """the magnitude of the data or the data itself if not a quantity.""" - data = self.da.data - return getattr(data, "magnitude", data) + return self.dequantify() @property def units(self): From 24a2c723c983951e0b2a35b14b9f555a306327a5 Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 6 Jun 2022 13:49:47 +0200 Subject: [PATCH 2/3] update the tests --- pint_xarray/tests/test_accessors.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pint_xarray/tests/test_accessors.py b/pint_xarray/tests/test_accessors.py index a457ed09..605ebddf 100644 --- a/pint_xarray/tests/test_accessors.py +++ b/pint_xarray/tests/test_accessors.py @@ -191,11 +191,12 @@ class TestPropertiesDataArray: def test_magnitude_getattr(self, example_quantity_da): da = example_quantity_da actual = da.pint.magnitude - assert not isinstance(actual, Quantity) + assert isinstance(actual, xr.DataArray) + assert not isinstance(actual.data, Quantity) def test_magnitude_getattr_unitless(self, example_unitless_da): da = example_unitless_da - xr.testing.assert_duckarray_equal(da.pint.magnitude, da.data) + xr.testing.assert_identical(da.pint.magnitude, da) def test_units_getattr(self, example_quantity_da): da = example_quantity_da From cb450a3159ac911dac19125c59d72985aff6f948 Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 6 Jun 2022 21:10:01 +0200 Subject: [PATCH 3/3] update whats-new.rst --- docs/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/whats-new.rst b/docs/whats-new.rst index a6381bbd..5c0b7c1c 100644 --- a/docs/whats-new.rst +++ b/docs/whats-new.rst @@ -10,6 +10,8 @@ What's new By `Justus Magin `_. - preserve :py:class:`pandas.MultiIndex` objects (:issue:`164`, :pull:`168`). By `Justus Magin `_. +- return a :py:class:`DataArray` from :py:attr:`DataArray.pint.magnitude` (:issue:`151`, :pull:`172`) + By `Justus Magin `_. 0.2.1 (26 Jul 2021) -------------------