diff --git a/src/rtctools/data/timeseries.py b/src/rtctools/data/timeseries.py index a6cbc4c..4d1bd0a 100644 --- a/src/rtctools/data/timeseries.py +++ b/src/rtctools/data/timeseries.py @@ -82,5 +82,7 @@ def fill_nan_in_timeseries(times: List[datetime], values: np.ndarray, interp_arg interp_args = {} times_sec = np.array([(t - times[0]).total_seconds() for t in times]) nans = np.isnan(values) + if all(nans): + return values result = np.interp(times_sec, times_sec[~nans], values[~nans], **interp_args) return result diff --git a/tests/data/test_timeseries.py b/tests/data/test_timeseries.py index 54047b6..82308e3 100644 --- a/tests/data/test_timeseries.py +++ b/tests/data/test_timeseries.py @@ -65,3 +65,10 @@ def test_fill_nan_in_timeseries(self): result = fill_nan_in_timeseries(times, values) ref_result = np.array([1.0, 1.0, 2.0, 3.0, 3.0]) np.testing.assert_almost_equal(result, ref_result) + values = np.array([np.nan, 1.0, np.nan, np.nan, np.nan]) + result = fill_nan_in_timeseries(times, values) + ref_result = np.array([1.0, 1.0, 1.0, 1.0, 1.0]) + np.testing.assert_almost_equal(result, ref_result) + values = np.array([np.nan, np.nan, np.nan, np.nan, np.nan]) + result = fill_nan_in_timeseries(times, values) + assert all(np.isnan(result))