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

Fix Var.weighted_average_lat bug with NaN and FT32 #203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ph-kev
Copy link
Member

@ph-kev ph-kev commented Feb 27, 2025

In the function Var.weighted_average_lat, if latitudes is in Float32 and there are NaNs in the data, then eventually the computation being done is Vector{Real} times Vector{Float32} which gives Vector{Real}. Then, nanmean is computed on this vector, but throw an error since there is no function defined for that type.

@ph-kev ph-kev force-pushed the kp/weighted-lat-bug branch from 8bb8cd6 to 208546b Compare February 27, 2025 01:13
@ph-kev ph-kev marked this pull request as ready for review February 27, 2025 01:18
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.25%. Comparing base (7513972) to head (d158ebe).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #203   +/-   ##
=======================================
  Coverage   98.25%   98.25%           
=======================================
  Files          12       12           
  Lines        1263     1263           
=======================================
  Hits         1241     1241           
  Misses         22       22           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@AlexisRenchon AlexisRenchon left a comment

Choose a reason for hiding this comment

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

Thank you Kevin!

@Sbozzolo
Copy link
Member

Sbozzolo commented Mar 3, 2025

Could you add your PR message to the commit message? This way, if people try to understand why you needed to change from 1 to 1.0 they can do that directly from the git log

Copy link
Member

@Sbozzolo Sbozzolo left a comment

Choose a reason for hiding this comment

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

Feel free to merge after you address the comment above

@ph-kev ph-kev force-pushed the kp/weighted-lat-bug branch from 208546b to 843fa90 Compare March 3, 2025 19:07
If there is an `OutputVar` whose latitudes are in `Float32` and the data
contains a `NaN`, then `Var.weighted_average_lat` creates `weights_1d`
whose type is `Vector{Float32}` and `nan_mask` whose type is
`Vector{Real}`. Note that `nan_mask = ifelse.(isnan.(var.data), NaN, 1)`
is a `Vector{Real}`, because `NaN` is a `Float64` and `1` is a `Int64`.
Then, the computation `nanmean(nan_mask[index_tuple...] .* weights_1d)`
throws an error, because `nan_mask[index_tuple...] .* weights_1d` is a
`Vector{Real}` and `nanmean` is not defined for `Vector{Real}`.
@ph-kev ph-kev force-pushed the kp/weighted-lat-bug branch from 843fa90 to d158ebe Compare March 4, 2025 00:42
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.

3 participants