Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fork #1

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/openeo_processes/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,14 @@ def exec_np(data, condition=None, context=None, dimension=0):

"""
if condition is None:
count = np.sum(is_valid(data), axis=dimension)
elif condition is True: # explicit check needed
condition = is_valid
if condition is True: # explicit check needed
count = data.shape[dimension]
elif callable(condition):
context = context if context is not None else {}
data = condition(data, **context)
count = np.sum(data, axis=dimension)
count = sum(1 for x in data if condition(x, **context))
else:
err_msg = "Data type of condition is not supported."
raise ValueError(err_msg)
raise ValueError(condition)

return count

Expand Down
4 changes: 3 additions & 1 deletion tests/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def test_array_element(self):
def test_count(self):
""" Tests `count` function. """
assert oeop.count([]) == 0
assert oeop.count([], condition=True) == 0
assert oeop.count([1, 0, 3, 2]) == 4
assert oeop.count(["ABC", np.nan]) == 1
assert oeop.count([False, np.nan], condition=True) == 2
assert oeop.count([0, 1, 2, 3, 4, 5, np.nan], condition=oeop.gt, context={'y': 2})
assert oeop.count([0, 1, 2, 3, 4, 5, np.nan], condition=oeop.gt, context={'y': 2}) == 3
assert oeop.count([0, 1, 2, 3, 4, 5, np.nan], condition=oeop.lte, context={'y': 2}) == 3

#TODO: add test
def test_array_apply(self):
Expand Down