Skip to content

Commit

Permalink
timeseries: update fill nans for case of all nans
Browse files Browse the repository at this point in the history
Update fill_nan_in_timeseries for the case where the timeseries
has only nans.
In this case, the result should also only be nans.
  • Loading branch information
SGeeversAtVortech committed Nov 15, 2024
1 parent 23b0573 commit 698d354
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rtctools/data/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions tests/data/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 698d354

Please sign in to comment.