From 4d1ed8287f19f0b6bb3840274782c0feb68323f0 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Fri, 9 Feb 2024 10:09:57 +0100 Subject: [PATCH] Inline _interp_time to avoid confusion --- modelskill/model/point.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/modelskill/model/point.py b/modelskill/model/point.py index b0e10cd1a..926c4bb0e 100644 --- a/modelskill/model/point.py +++ b/modelskill/model/point.py @@ -144,7 +144,12 @@ def _get_valid_times( df["idx"] = range(len(df)) # for query times get available left and right index of source times - df = _interp_time(df, obs_index).dropna() + df = ( + df.reindex(df.index.union(obs_index)) + .interpolate(method="time", limit_area="inside") + .reindex(obs_index) + .dropna() + ) df["idxa"] = np.floor(df.idx).astype(int) df["idxb"] = np.ceil(df.idx).astype(int) @@ -158,11 +163,3 @@ def _get_valid_times( return df[valid_idx].index -def _interp_time(df: pd.DataFrame, new_time: pd.DatetimeIndex) -> pd.DataFrame: - """Interpolate time series to new time index""" - new_df = ( - df.reindex(df.index.union(new_time)) - .interpolate(method="time", limit_area="inside") - .reindex(new_time) - ) - return new_df