From 35b015ce307f1eb12000981ec62ead8009b21cbe Mon Sep 17 00:00:00 2001 From: ValentinaHutter Date: Wed, 18 Sep 2024 11:35:09 +0200 Subject: [PATCH] update array_find --- .../process_implementations/arrays.py | 6 ++++++ tests/test_arrays.py | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/openeo_processes_dask/process_implementations/arrays.py b/openeo_processes_dask/process_implementations/arrays.py index c66b5546..729a44f6 100644 --- a/openeo_processes_dask/process_implementations/arrays.py +++ b/openeo_processes_dask/process_implementations/arrays.py @@ -190,6 +190,12 @@ def array_find( mask = ~np.array((data == value).any(axis=axis)) if np.isnan(value): mask = True + if reverse: + if axis is None: + size = data.size + else: + size = data.shape[axis] + idxs = size - 1 - idxs logger.warning( "array_find: numpy has no sentinel value for missing data in integer arrays, therefore np.masked_array is used to return the indices of found elements. Further operations might fail if not defined for masked arrays." diff --git a/tests/test_arrays.py b/tests/test_arrays.py index 0152ac09..6f9fc857 100644 --- a/tests/test_arrays.py +++ b/tests/test_arrays.py @@ -222,14 +222,14 @@ def test_array_contains_object_dtype(): [ ([1, 0, 3, 2], 3, 2, None, False), ([1, 0, 3, 2, np.nan, 3], np.nan, 999999, None, False), - ([1, 0, 3, 2], 3, 2, None, False), + ([1, 0, 3, 0, 2], 0, 1, None, False), ([[1, 0, 3, 2], [5, 3, 6, 8]], 3, [999999, 1, 0, 999999], 0, False), ([[1, 0, 3, 2], [5, 3, 6, 8]], 3, [2, 1], 1, False), - ([1, 0, 3, 2], 3, 1, None, True), + ([1, 0, 3, 2], 3, 2, None, True), ([1, 0, 3, 2, np.nan, 3], np.nan, 999999, None, True), - ([1, 0, 3, 2], 3, 1, None, True), - ([[1, 0, 3, 2], [5, 3, 6, 8]], 3, [999999, 0, 1, 999999], 0, True), - ([[1, 0, 3, 2], [5, 3, 6, 8]], 3, [1, 2], 1, True), + ([1, 0, 3, 0, 2], 0, 3, None, True), + ([[1, 0, 3, 2], [5, 3, 6, 8]], 3, [999999, 1, 0, 999999], 0, True), + ([[1, 0, 3, 2], [5, 3, 6, 8]], 3, [2, 1], 1, True), ], ) def test_array_find(data, value, expected, axis, reverse):