You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Builds in PR #467 are currently failing on TestPrecipAccumulation. They were not failing on my laptop until I updated pint from 0.11 to 0.12 and now I can reproduce the issue.
Pint 0.12 was released at 11:43 today.
TestPrecipAccumulation.test_3d_data_with_nans is failing with traceback:
___________________________________ TestPrecipAccumulation.test_3d_data_with_nans ____________________________________
self = <test_precip.TestPrecipAccumulation object at 0x7fd154327280>
def test_3d_data_with_nans(self):
# test with 3d data
pr = xr.open_dataset(self.nc_pr).pr # mm/s
prMM = xr.open_dataset(self.nc_pr).pr
prMM *= 86400
prMM.attrs["units"] = "mm/day"
# put a nan somewhere
prMM.values[10, 1, 0] = np.nan
pr.values[10, 1, 0] = np.nan
out1 = atmos.precip_accumulation(pr, freq="MS")
out2 = atmos.precip_accumulation(prMM, freq="MS")
# test kg m-2 s-1
pr.attrs["units"] = "kg m-2 s-1"
out3 = atmos.precip_accumulation(pr, freq="MS")
np.testing.assert_array_almost_equal(out1, out2, 3)
> np.testing.assert_array_almost_equal(out1, out3)
E AssertionError:
E Arrays are not almost equal to 6 decimals
E
E Mismatched elements: 58580 / 157248 (37.3%)
E Max absolute difference: 1.49309635e-05
E Max relative difference: 5.91187429e-08
E x: array([[[ 79.099993, 78.069995, 76.660005, ..., 72.889999,
E 71.969998, 70.510003],
E [ nan, 78.829994, 77.469998, ..., 73.349994,...
E y: array([[[ 79.09999 , 78.06999 , 76.66 , ..., 72.89 ,
E 71.97 , 70.51 ],
E [ nan, 78.829994, 77.47 , ..., 73.34999 ,...
tests/test_precip.py:86: AssertionError
The text was updated successfully, but these errors were encountered:
Found the bug:
At the end of precip_accumulation, data is converted to mm by multiplying by 1 day. In the failing test, out1 is in mm/s and out3 in kg m-2 s-1 which are identical normally. However, the conversion of the former is done by the default registry of pint, while the latter is from a xclim-added conversion function in xclim.core.units. Before pint 0.12, both were identical and ended by a multiplication by 86400.0, this factor being a python float (float32). In pint 0.12, the mm/s conversion factor is now an integer (int64) instead. When multiplied to the float32 test data, the output is casted to float64 whereas a multiplication with a float32 gives a float32.
Description
Builds in PR #467 are currently failing on
TestPrecipAccumulation
. They were not failing on my laptop until I updated pint from 0.11 to 0.12 and now I can reproduce the issue.Pint 0.12 was released at 11:43 today.
TestPrecipAccumulation.test_3d_data_with_nans
is failing with traceback:The text was updated successfully, but these errors were encountered: