diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 2308f9edb4328..a234bf9800844 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -86,6 +86,8 @@ Tick, ) +from pandas.core.reshape.concat import concat + _shared_docs_kwargs: Dict[str, str] = {} @@ -859,6 +861,11 @@ def interpolate( Interpolate values according to different methods. """ result = self._upsample("asfreq") + if isinstance(result.index, DatetimeIndex): + obj = self._selected_obj + tmp = concat([obj, result]).sort_index().interpolate(method='time') + tmp = tmp[result.index] + result[...] = tmp[~tmp.index.duplicated(keep='first')] return result.interpolate( method=method, axis=axis, diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index cbf69696d5801..0b4a9bd10e0bf 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -1816,3 +1816,14 @@ def test_resample_aggregate_functions_min_count(func): index=DatetimeIndex(["2020-03-31"], dtype="datetime64[ns]", freq="Q-DEC"), ) tm.assert_series_equal(result, expected) + + +def timeseries_interpolation(): + dates1 = date_range('2016-08-28', periods=4, freq='21H') + ts1 = Series([21 * i for i in range(4)], dates1, dtype=float) + nb_periods = (21 * 4) // 15 + dates2 = date_range('2016-08-28', periods=nb_periods, freq='15H') + expect = Series([15 * i for i in range(nb_periods)], dates2, dtype=float) + + result = ts1.resample('15H').interpolate(method='time') + tm.assert_series_equal(result, expect)