Skip to content

Ensure that _nanmean_mapreduce! inserts nans for zero counts#60

Merged
brenhinkeller merged 1 commit intobrenhinkeller:mainfrom
JamesWrigley:nanmean-mapreduce
May 27, 2025
Merged

Ensure that _nanmean_mapreduce! inserts nans for zero counts#60
brenhinkeller merged 1 commit intobrenhinkeller:mainfrom
JamesWrigley:nanmean-mapreduce

Conversation

@JamesWrigley
Copy link
Contributor

@JamesWrigley JamesWrigley commented May 27, 2025

Also added some more tests for nansum. In doing so I noticed that nansum will always give 0 instead of nan, which always annoyed me in numpy 😛 Maybe we could change that in a later version? It'd be breaking though, and if people expect that behaviour then we'd need a way to opt in/out.

Fixes #59.

Also added some more tests for `nansum`.
@brenhinkeller brenhinkeller merged commit 5535c28 into brenhinkeller:main May 27, 2025
7 checks passed
@JamesWrigley JamesWrigley deleted the nanmean-mapreduce branch May 27, 2025 22:38
@brenhinkeller
Copy link
Owner

Ah yeah, nansum returning zeros for all-nan arrays was intentional, as an extension of the analogy between counting and summing (and I guess it's nice that it matches numpy), but if there's strong demand we could consider changing it or adding a kwarg to select

B[i] = nan_value
else
B[i] /= counts[i]
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a problem for later, but I think you can probably avoid the branch entirely and just still use B[i] /= counts[i] since 0/0 is NaN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool, I didn't realize that.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug with nanmean

2 participants