Skip to content

Commit

Permalink
update array_find
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinaHutter committed Sep 18, 2024
1 parent 712cf10 commit 35b015c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions openeo_processes_dask/process_implementations/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
10 changes: 5 additions & 5 deletions tests/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 35b015c

Please sign in to comment.