FYI: Xarray's .sum()
will convert nan
to 0 if all values are nan
in a slice, which can affect comparison with CDAT summing results
#612
tomvothecoder
started this conversation in
4. General
Replies: 2 comments 4 replies
-
Just to make sure I understand: If an array has |
Beta Was this translation helpful? Give feedback.
3 replies
-
Yet another example of what happens when you rely on NaNs, rather than on masks ? Though I confess that the documentation of ma.MaskedArray.sum is not very detailed. You need to know that the operations will only take the non-masked elements into account, but this is also what you expect |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Overview
I've ran into this a few times while migrating production code for
e3sm_diags
ande3sm_to_cmip
from CDAT to Xarray/xCDATI compare two netCDF, one from Xarray and one from CDAT (post-summing) using
np.testing.assert_all_close()
. However, I getx and y nan location mismatch
because Xarray replacesnan
with 0s while CDAT maintainsnan
(if all values arenan
for a slice).Example:
Reason why Xarray's
.sum()
replacesnan
with 0Workaround (if you need to compare CDAT vs. Xarray/xCDAT sum results)
skipna
andmin_count
arg, for example.sum(..., skipna=True, min_count=1)
.np.sum()
directly on the.values
of thexr.DataArray
and rebuild thexr.DataArray
object with those results (example).Related posts:
Beta Was this translation helpful? Give feedback.
All reactions