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

all/any: Return value for empty arrays? #494

Open
m-mohr opened this issue Jan 5, 2024 · 0 comments
Open

all/any: Return value for empty arrays? #494

m-mohr opened this issue Jan 5, 2024 · 0 comments

Comments

@m-mohr
Copy link
Member

m-mohr commented Jan 5, 2024

Process ID: all / any

Describe the issue:
The processes all and any return null for empty arrays in openEO

I think the thought was to express that an empty array means no-data, e.g. all([]) -> null, but also all([null], ignore_nodata = false) -> null (here: null = no-data value). So that an empty array has the same meaning as an array with solely no-data values (if not ignored).

This still makes sense, but it is not consistent with common languages though:

all([]) any([]) Note
Python true false
R true false use c() instead of []
Julia true false
JavaScript true false all is [].every(x => x) and any is [].some(x => x)
Java true false all is allMatch and any is anyMatch

Note: in JS all is [].every(x => x) and any is [].some(x => x)

According to ChatGPT this is also the case for C++, C#, Ruby, Haskell, Perl, Groovy, Scala, and Kotlin.

ChatGPT also says:

The choice between returning True/False or NoData depends on the context of the application and the specific requirements of the data processing or logical evaluation being performed. In most programming scenarios, True/False is preferred for its logical consistency. However, in data analysis, scientific computing, or situations where the distinction between "no data" and "a definitive answer" is significant, returning a NoData value might be more appropriate.

Proposed solution:
We should discuss whether to update all to return true and any to return false for empty arrays. I'm not sure myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant