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
2 changes: 2 additions & 0 deletions docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ What's new
By `Justus Magin <https://github.com/keewis>`_.
- Added the :py:func:`pint_xarray.expects` decorator to allow wrapping quantity-unaware functions (:issue:`141`, :pull:`316`).
By `Justus Magin <https://github.com/keewis>`_ and `Tom Nicholas <https://github.com/TomNicholas>`_.
- Follow the change in signature of :py:meth:`xarray.Index.equals` (:issue:`322`, :pull:`324`)
By `Justus Magin <https://github.com/keewis>`_.

0.5.1 (10 Aug 2025)
-------------------
Expand Down
8 changes: 5 additions & 3 deletions pint_xarray/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ def join(self, other, how="inner"):
def reindex_like(self, other):
raise NotImplementedError()

def equals(self, other):
def equals(self, other, *, exclude=None):
if not isinstance(other, PintIndex):
return False

# for now we require exactly matching units to avoid the potentially expensive conversion
if self.units != other.units:
return False

# last to avoid the potentially expensive comparison
return self.index.equals(other.index)
# Explicitly pass `exclude`, the index does not officially support
# indexes other than the PandasIndex
# Last to avoid the potentially expensive comparison
return self.index.equals(other.index, exclude=exclude)

def roll(self, shifts):
return self._replace(self.index.roll(shifts))
Expand Down
22 changes: 22 additions & 0 deletions pint_xarray/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,28 @@ def test_equals(other, expected):
assert actual == expected


@pytest.mark.filterwarnings("error")
def test_align_equals_warning():
index1 = PintIndex(
index=PandasIndex(pd.Index([1, 2]), dim="x"),
units={"x": ureg.Unit("m")},
)
index2 = PintIndex(
index=PandasIndex(pd.Index([0, 1, 2]), dim="y"),
units={"y": ureg.Unit("m")},
)

ds = xr.Dataset(
{"a": (["y", "x"], [[-1, 1], [0, 2], [1, 3]])},
coords=xr.Coordinates(
{"x": [1, 2], "y": [0, 1, 2]}, indexes={"x": index1, "y": index2}
),
)

# trigger comparison
ds["a"] * ds["x"] * ds["y"]


@pytest.mark.parametrize(
["shifts", "expected_index"],
(
Expand Down
Loading
Loading