Skip to content

Commit 1ed633e

Browse files
authored
follow the change in signature of xarray.Index.equals (#324)
* adapt to the newer API of equals * add pooch and netcdf4 to the dev env * trigger the future warning * changelog * comment on the passing of exclude (since that will break for indexes that don't support `exclude`)
1 parent 325c600 commit 1ed633e

File tree

5 files changed

+1087
-1017
lines changed

5 files changed

+1087
-1017
lines changed

docs/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ What's new
2020
By `Justus Magin <https://github.com/keewis>`_.
2121
- Added the :py:func:`pint_xarray.expects` decorator to allow wrapping quantity-unaware functions (:issue:`141`, :pull:`316`).
2222
By `Justus Magin <https://github.com/keewis>`_ and `Tom Nicholas <https://github.com/TomNicholas>`_.
23+
- Follow the change in signature of :py:meth:`xarray.Index.equals` (:issue:`322`, :pull:`324`)
24+
By `Justus Magin <https://github.com/keewis>`_.
2325

2426
0.5.1 (10 Aug 2025)
2527
-------------------

pint_xarray/index.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,18 @@ def join(self, other, how="inner"):
7171
def reindex_like(self, other):
7272
raise NotImplementedError()
7373

74-
def equals(self, other):
74+
def equals(self, other, *, exclude=None):
7575
if not isinstance(other, PintIndex):
7676
return False
7777

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

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

8587
def roll(self, shifts):
8688
return self._replace(self.index.roll(shifts))

pint_xarray/tests/test_index.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,28 @@ def test_equals(other, expected):
205205
assert actual == expected
206206

207207

208+
@pytest.mark.filterwarnings("error")
209+
def test_align_equals_warning():
210+
index1 = PintIndex(
211+
index=PandasIndex(pd.Index([1, 2]), dim="x"),
212+
units={"x": ureg.Unit("m")},
213+
)
214+
index2 = PintIndex(
215+
index=PandasIndex(pd.Index([0, 1, 2]), dim="y"),
216+
units={"y": ureg.Unit("m")},
217+
)
218+
219+
ds = xr.Dataset(
220+
{"a": (["y", "x"], [[-1, 1], [0, 2], [1, 3]])},
221+
coords=xr.Coordinates(
222+
{"x": [1, 2], "y": [0, 1, 2]}, indexes={"x": index1, "y": index2}
223+
),
224+
)
225+
226+
# trigger comparison
227+
ds["a"] * ds["x"] * ds["y"]
228+
229+
208230
@pytest.mark.parametrize(
209231
["shifts", "expected_index"],
210232
(

0 commit comments

Comments
 (0)