diff --git a/openeo_processes_dask/process_implementations/exceptions.py b/openeo_processes_dask/process_implementations/exceptions.py index b13aac5e..b7057a82 100644 --- a/openeo_processes_dask/process_implementations/exceptions.py +++ b/openeo_processes_dask/process_implementations/exceptions.py @@ -92,3 +92,7 @@ class LabelMismatch(OpenEOException): class KernelDimensionsUneven(OpenEOException): pass + + +class MinMaxSwapped(OpenEOException): + pass diff --git a/openeo_processes_dask/process_implementations/math.py b/openeo_processes_dask/process_implementations/math.py index 1bc927f7..931e6746 100644 --- a/openeo_processes_dask/process_implementations/math.py +++ b/openeo_processes_dask/process_implementations/math.py @@ -7,6 +7,7 @@ _is_dask_array, ) from openeo_processes_dask.process_implementations.exceptions import ( + MinMaxSwapped, OpenEOException, QuantilesParameterConflict, QuantilesParameterMissing, @@ -263,6 +264,10 @@ def extrema(data, ignore_nodata=True, axis=None, keepdims=False): def clip(x, min, max): + if min > max: + raise MinMaxSwapped( + "The minimum value should be lower than or equal to the maximum value." + ) # Cannot use positional arguments to pass min and max into np.clip, this will not work with dask. return np.clip(x, min, max) diff --git a/tests/test_math.py b/tests/test_math.py index a9cffceb..4d5bb6bb 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -2,6 +2,7 @@ import numpy as np import pytest +from openeo_processes_dask.process_implementations.exceptions import MinMaxSwapped from openeo_processes_dask.process_implementations.math import * @@ -86,3 +87,5 @@ def test_clip(): result_dask = clip(dask_array, min=0, max=2) assert np.array_equal(result_np, result_dask.compute(), equal_nan=True) assert np.array_equal(result_np, np.array([2, 0])) + with pytest.raises(MinMaxSwapped): + clip(dask_array, 10, 0)