csdms / pymt

A Python toolkit for running and coupling Earth surface models
https://pymt.readthedocs.io
MIT License
52 stars 20 forks source link

TimeInterpolator tests fail because of changes to scipy.interpolation.interp1d #162

Closed mdpiper closed 1 month ago

mdpiper commented 2 years ago

Two TimeInterpolator tests are failing. The traceback:

===================================== FAILURES ======================================
__________________________ test_interp_outside_range[next] __________________________
Traceback (most recent call last):
  File "/home/mpiper/projects/pymt/tests/framework/test_timeinterp.py", line 88, in test_interp_outside_range
    assert np.isfinite(interp(4.5)) and interp(4.5) >= 4.0
AssertionError: assert (False)
 +  where False = <ufunc 'isfinite'>(array(nan))
 +    where <ufunc 'isfinite'> = np.isfinite
 +    and   array(nan) = <pymt.framework.timeinterp.TimeInterpolator object at 0x7fe5596021a0>(4.5)
_________________________ test_interp_below_range[previous] _________________________
Traceback (most recent call last):
  File "/home/mpiper/projects/pymt/tests/framework/test_timeinterp.py", line 96, in test_interp_below_range
    assert np.isfinite(interp(-0.5)) and interp(-0.5) >= 4.0
AssertionError: assert (False)
 +  where False = <ufunc 'isfinite'>(array(nan))
 +    where <ufunc 'isfinite'> = np.isfinite
 +    and   array(nan) = <pymt.framework.timeinterp.TimeInterpolator object at 0x7fe5596012a0>(-0.5)

The problem lies with the behavior of the previous and next methods of scipy.interpolate.interp1d, which TimeInterpolator uses. The issue https://github.com/scipy/scipy/issues/16997 explains the old (scipy<1.9) and new (scipy>=1.9) behavior of these methods. It looks like the new behavior is expected, so we'll need to update our tests.

mdpiper commented 1 year ago

A workaround is to require scipy<1.9.