Skip to content

Commit 2dc635f

Browse files
authored
TST/COMPAT: allow small tolerance in image comparison, equals signature compatibility (#119)
* TST: allow small tolerance in image comparison * xarray compat
1 parent 49a0c89 commit 2dc635f

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

xvec/index.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,14 @@ def sel(
227227
# (see https://github.com/pydata/xarray/issues/7099)
228228
return self._sel_sindex(labels, method, tolerance) # type: ignore
229229

230-
def equals(self, other: Index) -> bool:
230+
def equals(
231+
self, other: Index, *, exclude: frozenset[Hashable] | None = None
232+
) -> bool:
231233
if not isinstance(other, GeometryIndex):
232234
return False
233235
if not self._check_crs(other.crs, allow_none=True):
234236
return False
235-
return self._index.equals(other._index)
237+
return self._index.equals(other._index, exclude=exclude)
236238

237239
def join(
238240
self: GeometryIndex, other: GeometryIndex, how: str = "inner"

xvec/tests/test_plotting.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def glaciers():
3737
)
3838

3939

40-
@image_comparison(baseline_images=["col"], extensions=["png"], style=[])
40+
@image_comparison(baseline_images=["col"], extensions=["png"], style=[], tol=0.01)
4141
def test_col(aggregated):
4242
f, ax = aggregated.v.sel(month=1).xvec.plot(col="level")
4343

@@ -48,7 +48,7 @@ def test_col(aggregated):
4848
assert ax0.get_title() == "level = 200"
4949

5050

51-
@image_comparison(baseline_images=["colwrap"], extensions=["png"], style=[])
51+
@image_comparison(baseline_images=["colwrap"], extensions=["png"], style=[], tol=0.01)
5252
def test_colwrap(aggregated):
5353
f, ax = aggregated.u.sel(month=1).xvec.plot(col="level", col_wrap=2)
5454

@@ -58,7 +58,7 @@ def test_colwrap(aggregated):
5858
assert ax[0][0].get_title() == "level = 200"
5959

6060

61-
@image_comparison(baseline_images=["col_row"], extensions=["png"], style=[])
61+
@image_comparison(baseline_images=["col_row"], extensions=["png"], style=[], tol=0.01)
6262
def test_col_row(aggregated):
6363
f, ax = aggregated.v.xvec.plot(col="month", row="level")
6464

@@ -70,15 +70,15 @@ def test_col_row(aggregated):
7070
assert ax[0][1].get_ylabel() == "level = 200"
7171

7272

73-
@image_comparison(baseline_images=["1d"], extensions=["png"], style=[])
73+
@image_comparison(baseline_images=["1d"], extensions=["png"], style=[], tol=0.01)
7474
def test_1d(aggregated):
7575
f, ax = aggregated.z.sel(level=200, month=1).xvec.plot()
7676

7777
assert ax.get_xlabel() == "Geodetic longitude\n[degree]"
7878
assert ax.get_ylabel() == "Geodetic latitude\n[degree]"
7979

8080

81-
@image_comparison(baseline_images=["var_geom"], extensions=["png"], style=[])
81+
@image_comparison(baseline_images=["var_geom"], extensions=["png"], style=[], tol=0.01)
8282
def test_var_geom(glaciers):
8383
f, ax = glaciers.geometry.xvec.plot(col="year")
8484

@@ -89,7 +89,9 @@ def test_var_geom(glaciers):
8989
assert ax0.get_title() == "year = 1936.0"
9090

9191

92-
@image_comparison(baseline_images=["var_geom_facet"], extensions=["png"], style=[])
92+
@image_comparison(
93+
baseline_images=["var_geom_facet"], extensions=["png"], style=[], tol=0.01
94+
)
9395
def test_var_geom_facet(glaciers):
9496
f, ax = glaciers.geometry.xvec.plot(col="name", row="year")
9597

@@ -100,7 +102,9 @@ def test_var_geom_facet(glaciers):
100102
assert ax[0][-1].get_ylabel() == "year = 1936.0"
101103

102104

103-
@image_comparison(baseline_images=["var_geom_ds"], extensions=["png"], style=[])
105+
@image_comparison(
106+
baseline_images=["var_geom_ds"], extensions=["png"], style=[], tol=0.01
107+
)
104108
def test_var_geom_ds(glaciers):
105109
f, ax = glaciers.xvec.plot(col="year", geometry="geometry")
106110

@@ -111,7 +115,7 @@ def test_var_geom_ds(glaciers):
111115
assert ax0.get_title() == "year = 1936.0"
112116

113117

114-
@image_comparison(baseline_images=["hue"], extensions=["png"], style=[])
118+
@image_comparison(baseline_images=["hue"], extensions=["png"], style=[], tol=0.01)
115119
def test_hue(glaciers):
116120
f, ax = glaciers.xvec.plot(col="year", geometry="geometry", hue="fwidth")
117121

@@ -122,7 +126,9 @@ def test_hue(glaciers):
122126
assert ax0.get_title() == "year = 1936.0"
123127

124128

125-
@image_comparison(baseline_images=["geom_switching"], extensions=["png"], style=[])
129+
@image_comparison(
130+
baseline_images=["geom_switching"], extensions=["png"], style=[], tol=0.01
131+
)
126132
def test_geom_switching(glaciers):
127133
glaciers_w_sum = glaciers.xvec.summarize_geometry(
128134
dim="name", geom_array="geometry", aggfunc="concave_hull", ratio=0.25

0 commit comments

Comments
 (0)