-
Notifications
You must be signed in to change notification settings - Fork 904
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
Extend TimeSeries.resample() to support more resampling methods #2643
base: master
Are you sure you want to change the base?
Conversation
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.
Nice contribution @jonasblanc, some minor comments to improve the readibility
'pad': propagate last valid observation forward to next valid | ||
|
||
'backfill': use NEXT valid observation to fill. | ||
Method to either aggregate grouped values (for down-sampling) or fill holes (for up-sampling) |
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.
let's chaneg the type from str
to Literal
, it will simplify the sanity checks. Since there are a lot of possible values, we could use a constant/alias to store them.
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.
As discussed waiting for @dennisbader opinion on this. Typing as Literal is not sufficient for sanity check of method
. So it would look something like this.
ResamplingMethod = Literal["all", ... "var",]
def resample(
self, freq: Union[str, pd.DateOffset], method: ResamplingMethod = "pad", **kwargs
) -> Self:
...
if method in get_args(ResamplingMethod):
...
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2643 +/- ##
==========================================
- Coverage 94.20% 94.17% -0.04%
==========================================
Files 141 141
Lines 15491 15494 +3
==========================================
- Hits 14594 14592 -2
- Misses 897 902 +5 ☔ View full report in Codecov by Sentry. |
Checklist before merging this PR:
Fixes #699
Summary
TimeSeries.resample()
.method_args
.Other Information
asfreq
is used for down-sampling.any()
andall()
aggregation methods, to be consistent withTimeSeries
, I castbool
back toint
after the aggregation.pad
as the default method so as not to break the default behavior, even though it's not the most intuitive method for down-sampling.