Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ What's new
==========
0.6.1 (*unreleased*)
--------------------

- Properly rename the coordinate units (:pull:`351`).
By `Justus Magin <https://github.com/keewis>`_.

0.6.0 (31 Aug 2025)
-------------------
Expand Down
5 changes: 4 additions & 1 deletion pint_xarray/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 3 additions & 2 deletions pint_xarray/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down