Skip to content

Commit 4e90851

Browse files
manugvsoxofaan
authored andcommitted
Renamed and removed optional argument.
1 parent 36de2be commit 4e90851

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

openeo/testing/results.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
_DEFAULT_RTOL = 1e-6
2222
_DEFAULT_ATOL = 1e-6
23-
_DEFAULT_PXTOL = 0.0
23+
_DEFAULT_PIXELTOL = 0.0
2424

2525
# https://paulbourke.net/dataformats/asciiart
2626
DEFAULT_GRAYSCALE_70_CHARACTERS = r"$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "[::-1]
@@ -196,7 +196,7 @@ def _compare_xarray_dataarray(
196196
*,
197197
rtol: float = _DEFAULT_RTOL,
198198
atol: float = _DEFAULT_ATOL,
199-
pxtol: Optional[float] = _DEFAULT_PXTOL,
199+
pixel_tolerance: float = _DEFAULT_PIXELTOL,
200200
name: str = None,
201201
) -> List[str]:
202202
"""
@@ -233,10 +233,10 @@ def _compare_xarray_dataarray(
233233
issues.append(f"Shape mismatch: {actual.shape} != {expected.shape}")
234234
compatible = len(issues) == 0
235235
try:
236-
if pxtol > _DEFAULT_PXTOL:
236+
if pixel_tolerance > _DEFAULT_PIXELTOL:
237237
assert (
238238
actual != expected
239-
).mean().item() <= pxtol, "Percentage number of pixels that are different is above the threshold"
239+
).mean().item() <= pixel_tolerance, "Percentage number of pixels that are different is above the threshold"
240240
else:
241241
xarray.testing.assert_allclose(a=actual, b=expected, rtol=rtol, atol=atol)
242242
except AssertionError as e:
@@ -281,7 +281,7 @@ def _compare_xarray_datasets(
281281
*,
282282
rtol: float = _DEFAULT_RTOL,
283283
atol: float = _DEFAULT_ATOL,
284-
pxtol: Optional[float] = _DEFAULT_PXTOL,
284+
pixel_tolerance: float = _DEFAULT_PIXELTOL,
285285
) -> List[str]:
286286
"""
287287
Compare two xarray ``DataSet``s with tolerance and report mismatch issues (as strings)
@@ -300,7 +300,9 @@ def _compare_xarray_datasets(
300300
all_issues.append(f"Xarray DataSet variables mismatch: {actual_vars} != {expected_vars}")
301301
for var in expected_vars.intersection(actual_vars):
302302
_log.debug(f"_compare_xarray_datasets: comparing variable {var!r}")
303-
issues = _compare_xarray_dataarray(actual[var], expected[var], rtol=rtol, atol=atol, pxtol=pxtol, name=var)
303+
issues = _compare_xarray_dataarray(
304+
actual[var], expected[var], rtol=rtol, atol=atol, pixel_tolerance=pixel_tolerance, name=var
305+
)
304306
if issues:
305307
all_issues.append(f"Issues for variable {var!r}:")
306308
all_issues.extend(issues)
@@ -397,7 +399,7 @@ def _compare_job_results(
397399
*,
398400
rtol: float = _DEFAULT_RTOL,
399401
atol: float = _DEFAULT_ATOL,
400-
pxtol: Optional[float] = _DEFAULT_PXTOL,
402+
pixel_tolerance: float = _DEFAULT_PIXELTOL,
401403
tmp_path: Optional[Path] = None,
402404
) -> List[str]:
403405
"""
@@ -427,14 +429,14 @@ def _compare_job_results(
427429
all_issues.extend(issues)
428430
elif expected_path.suffix.lower() in {".nc", ".netcdf"}:
429431
issues = _compare_xarray_datasets(
430-
actual=actual_path, expected=expected_path, rtol=rtol, atol=atol, pxtol=pxtol
432+
actual=actual_path, expected=expected_path, rtol=rtol, atol=atol, pixel_tolerance=pixel_tolerance
431433
)
432434
if issues:
433435
all_issues.append(f"Issues for file {filename!r}:")
434436
all_issues.extend(issues)
435437
elif expected_path.suffix.lower() in {".tif", ".tiff", ".gtiff", ".geotiff"}:
436438
issues = _compare_xarray_dataarray(
437-
actual=actual_path, expected=expected_path, rtol=rtol, atol=atol, pxtol=pxtol
439+
actual=actual_path, expected=expected_path, rtol=rtol, atol=atol, pixel_tolerance=pixel_tolerance
438440
)
439441
if issues:
440442
all_issues.append(f"Issues for file {filename!r}:")
@@ -478,7 +480,7 @@ def assert_job_results_allclose(
478480
*,
479481
rtol: float = _DEFAULT_RTOL,
480482
atol: float = _DEFAULT_ATOL,
481-
pxtol: Optional[float] = _DEFAULT_PXTOL,
483+
pixel_tolerance: float = _DEFAULT_PIXELTOL,
482484
tmp_path: Optional[Path] = None,
483485
):
484486
"""
@@ -490,7 +492,7 @@ def assert_job_results_allclose(
490492
:py:meth:`~openeo.rest.job.JobResults` object or path to directory with downloaded assets.
491493
:param rtol: relative tolerance
492494
:param atol: absolute tolerance
493-
:param pxtol: allowable tolerance for the number of pixels in percentage
495+
:param pixel_tolerance: allowable tolerance for fraction of pixels in percentage
494496
:param tmp_path: root temp path to download results if needed.
495497
It's recommended to pass pytest's `tmp_path` fixture here
496498
:raises AssertionError: if not equal within the given tolerance
@@ -500,6 +502,8 @@ def assert_job_results_allclose(
500502
.. warning::
501503
This function is experimental and subject to change.
502504
"""
503-
issues = _compare_job_results(actual, expected, rtol=rtol, atol=atol, pxtol=pxtol, tmp_path=tmp_path)
505+
issues = _compare_job_results(
506+
actual, expected, rtol=rtol, atol=atol, pixel_tolerance=pixel_tolerance, tmp_path=tmp_path
507+
)
504508
if issues:
505509
raise AssertionError("\n".join(issues))

0 commit comments

Comments
 (0)