Skip to content

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

@m-mohr

Description

@m-mohr

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions