Skip to content

Conversation

@Illviljan
Copy link
Contributor

@Illviljan Illviljan commented Jan 6, 2023

@github-actions github-actions bot added the topic-arrays related to flexible array support label Jan 6, 2023
@Illviljan
Copy link
Contributor Author

Illviljan commented Jan 6, 2023

The array api standard doesn't define any nan*-functions.
xarray pretty much always defaults to using nan*-function. :(

So any time an array has a __array_namespace__ we have to use our own nan-solution, like for .sum:

def sum_where(data, axis=None, dtype=None, where=None):
xp = get_array_namespace(data)
if where is not None:
a = where_method(xp.zeros_like(data), where, data)
else:
a = data
result = xp.sum(a, axis=axis, dtype=dtype)
return result

Any thoughts? Are there any clever ways to handle the aggregations with NaNs in a generic way?

edit: numpy implementations:
https://github.com/numpy/numpy/blob/main/numpy/lib/nanfunctions.py

@tomwhite
Copy link
Contributor

I was hoping https://github.com/data-apis/array-api-compat might help with this, but I'm not sure it does...

@tomwhite
Copy link
Contributor

Related issue: data-apis/array-api#621

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

Labels

topic-arrays related to flexible array support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some aggregate operations using the array API fail

2 participants