From 4eae837f5e6e86ab25d16c9f8164b938fa8e0709 Mon Sep 17 00:00:00 2001 From: ValentinaHutter <85164505+ValentinaHutter@users.noreply.github.com> Date: Tue, 31 Aug 2021 07:50:31 +0200 Subject: [PATCH] Update clip to handle nodata values --- src/openeo_processes/math.py | 5 +---- tests/test_math.py | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openeo_processes/math.py b/src/openeo_processes/math.py index 6efeffab..545900e7 100644 --- a/src/openeo_processes/math.py +++ b/src/openeo_processes/math.py @@ -3323,10 +3323,7 @@ def exec_xar(x, min, max): The value clipped to the specified range. """ - clip = x.where(x > min, min) - clip = clip.where(x < max, max) - - return clip + return x.clip(min = min, max = max) @staticmethod def exec_da(): diff --git a/tests/test_math.py b/tests/test_math.py index 41727c99..374a6af1 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -323,6 +323,9 @@ def test_clip(self): xr.testing.assert_equal( oeop.clip(self.test_data.xr_data_factor(1, 9), min=1, max=8), self.test_data.xr_data_factor(1, 8)) + xr.testing.assert_equal( + oeop.clip(self.test_data.xr_data_factor(np.nan, 9), min=1, max=8), + self.test_data.xr_data_factor(np.nan, 8)) def test_quantiles(self): """ Tests `quantiles` function. """