Skip to content

Commit 323f21b

Browse files
committed
Issue #864 only do pixel_tolerance check on numerical data
1 parent 650e8e1 commit 323f21b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

openeo/testing/results.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ def _compare_xarray_dataarray(
232232
if actual.shape != expected.shape:
233233
issues.append(f"Shape mismatch: {actual.shape} != {expected.shape}")
234234
compatible = len(issues) == 0
235+
is_numerical_data = numpy.issubdtype(actual.dtype, numpy.number) and numpy.issubdtype(expected.dtype, numpy.number)
235236
try:
236-
if pixel_tolerance and compatible:
237+
if pixel_tolerance and compatible and is_numerical_data:
237238
threshold = abs(expected * rtol) + atol
238239
bad_pixels = abs(actual * 1.0 - expected * 1.0) > threshold
239240
percentage_bad_pixels = bad_pixels.mean().item() * 100
@@ -320,6 +321,7 @@ def assert_xarray_dataset_allclose(
320321
*,
321322
rtol: float = _DEFAULT_RTOL,
322323
atol: float = _DEFAULT_ATOL,
324+
pixel_tolerance: float = _DEFAULT_PIXELTOL,
323325
):
324326
"""
325327
Assert that two Xarray ``DataSet`` instances are equal (with tolerance).
@@ -335,7 +337,9 @@ def assert_xarray_dataset_allclose(
335337
.. warning::
336338
This function is experimental and subject to change.
337339
"""
338-
issues = _compare_xarray_datasets(actual=actual, expected=expected, rtol=rtol, atol=atol)
340+
issues = _compare_xarray_datasets(
341+
actual=actual, expected=expected, rtol=rtol, atol=atol, pixel_tolerance=pixel_tolerance
342+
)
339343
if issues:
340344
raise AssertionError("\n".join(issues))
341345

tests/testing/test_results.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,21 @@ def test_assert_xarray_dataset_allclose_empty_coords_handling(self):
357357
)
358358
assert_xarray_dataset_allclose(actual=actual, expected=expected)
359359

360+
def test_assert_xarray_dataset_allclose_crs_variable(self):
361+
expected = xarray.Dataset(
362+
{
363+
"b02": xarray.DataArray([1, 2, 3]),
364+
"crs": xarray.DataArray(b"", attrs={"spatial_ref": "meh"}),
365+
}
366+
)
367+
actual = xarray.Dataset(
368+
{
369+
"b02": xarray.DataArray([1, 2, 3]),
370+
"crs": xarray.DataArray(b"", attrs={"spatial_ref": "meh"}),
371+
}
372+
)
373+
assert_xarray_dataset_allclose(actual=actual, expected=expected, pixel_tolerance=0.1)
374+
360375

361376
class TestAssertJobResults:
362377
@pytest.fixture

0 commit comments

Comments
 (0)