From 3aafa6a060da976242f79446e4b4f795859aa95f Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Fri, 21 Nov 2025 11:47:11 +0100 Subject: [PATCH 1/3] expect to have renamed the coordinate --- pint_xarray/tests/test_index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pint_xarray/tests/test_index.py b/pint_xarray/tests/test_index.py index 481fe7a5..1c9f6cf0 100644 --- a/pint_xarray/tests/test_index.py +++ b/pint_xarray/tests/test_index.py @@ -260,11 +260,12 @@ def test_roll(shifts, expected_index): @pytest.mark.parametrize("name_dict", ({"y2": "y3"}, {"y2": "y1"})) def test_rename(name_dict, dims_dict): wrapped_index = PandasIndex(pd.Index([1, 2], name="y2"), dim="y") - index = PintIndex(index=wrapped_index, units={"y": ureg.Unit("m")}) + index = PintIndex(index=wrapped_index, units={"y2": ureg.Unit("m")}) actual = index.rename(name_dict, dims_dict) expected = PintIndex( - index=wrapped_index.rename(name_dict, dims_dict), units=index.units + index=wrapped_index.rename(name_dict, dims_dict), + units={name_dict["y2"]: ureg.Unit("m")}, ) assert actual.equals(expected) From a8fc2919c99fa398c7bd38f880d27d17b6aecee8 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Fri, 21 Nov 2025 11:47:42 +0100 Subject: [PATCH 2/3] also rename the units --- pint_xarray/index.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pint_xarray/index.py b/pint_xarray/index.py index 7c233f3e..db031f83 100644 --- a/pint_xarray/index.py +++ b/pint_xarray/index.py @@ -112,7 +112,10 @@ def roll(self, shifts): return self._replace(self.index.roll(shifts)) def rename(self, name_dict, dims_dict): - return self._replace(self.index.rename(name_dict, dims_dict)) + new_units = {new: self.units[old] for old, new in name_dict.items()} + return self.__class__( + index=self.index.rename(name_dict, dims_dict), units=new_units + ) def __getitem__(self, indexer): return self._replace(self.index[indexer]) From be424b09efde5683a52a3d1db6d57f80c3324506 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Fri, 21 Nov 2025 11:51:35 +0100 Subject: [PATCH 3/3] changelog --- docs/whats-new.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/whats-new.rst b/docs/whats-new.rst index e91dae9e..a00ba543 100644 --- a/docs/whats-new.rst +++ b/docs/whats-new.rst @@ -4,7 +4,8 @@ What's new ========== 0.6.1 (*unreleased*) -------------------- - +- Properly rename the coordinate units (:pull:`351`). + By `Justus Magin `_. 0.6.0 (31 Aug 2025) -------------------