-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
correction to get time interpolation correct #39886
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are not following standard code guideines, e.g. use " instead of '. run |
||
return result.interpolate( | ||
method=method, | ||
axis=axis, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will not run as a test. pytest will run all files of the form test_*.py or *_test.py rename this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I have done 90 % of the job, now I let maintainers finishing it. It should take them minutes while it would take my hours to polish the PR. This bug has been reported 3 years ago and nobody from Pandas tried anything while a solution was proposed in the bug report. Now, 3 years after, I have done a PR. I know it is not perfect but it must be very close to what it should be. I hope it will not take 3 more years. @attack68 It is not against you. I don't want to become a maintainers but just to help at my level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @attack68 or any one else: feel free to for from my work and to finish the PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your imports are in the wrong order and causing failed checks.
run
> isort pandas