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

New Pint version causes test failures #468

Closed
aulemahal opened this issue May 29, 2020 · 2 comments · Fixed by #469
Closed

New Pint version causes test failures #468

aulemahal opened this issue May 29, 2020 · 2 comments · Fixed by #469
Assignees
Labels
bug Something isn't working

Comments

@aulemahal
Copy link
Collaborator

  • xclim version: master
  • Python version: 3.8
  • Operating System: linux

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:

___________________________________ 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
@aulemahal aulemahal added the bug Something isn't working label May 29, 2020
@Zeitsperre
Copy link
Collaborator

This has been a fun week for package maintenance.

@aulemahal
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants