-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
BUG: rolling.quantile does not return an interpolated result #16247
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fa971a2
BUG: rolling.quantile now returns an interpolated result (#9413)
guillemborrell ad8c034
Implemented changes suggested by reviewer @jaimefrio
18da308
quantile 1.0 and 0.0 are handled by the wrapper.
guillemborrell 69b0a48
Move entry in Whatsnew to Groupby/Resample/Rolling
guillemborrell 3acc6fd
Added benchmarks for rolling windows
b9dc329
Implemented changes suggested by reviewer @jaimefrio
b94bda2
quantile 1.0 and 0.0 are handled by the wrapper.
guillemborrell 79e905f
Move entry in Whatsnew to Groupby/Resample/Rolling
guillemborrell fa4e036
Added benchmarks for rolling windows
b99e2be
Fixed whatsnew syntax and comments on new tests.
guillemborrell 4080942
Fixed trailing whitespace to make the linter happy
guillemborrell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
from .pandas_vb_common import * | ||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
class DataframeRolling(object): | ||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.N = 100000 | ||
self.Ns = 10000 | ||
self.df = pd.DataFrame({'a': np.random.random(self.N)}) | ||
self.dfs = pd.DataFrame({'a': np.random.random(self.Ns)}) | ||
self.wins = 10 | ||
self.winl = 1000 | ||
|
||
def time_rolling_quantile_0(self): | ||
(self.df.rolling(self.wins).quantile(0.0)) | ||
|
||
def time_rolling_quantile_1(self): | ||
(self.df.rolling(self.wins).quantile(1.0)) | ||
|
||
def time_rolling_quantile_median(self): | ||
(self.df.rolling(self.wins).quantile(0.5)) | ||
|
||
def time_rolling_median(self): | ||
(self.df.rolling(self.wins).median()) | ||
|
||
def time_rolling_median(self): | ||
(self.df.rolling(self.wins).mean()) | ||
|
||
def time_rolling_max(self): | ||
(self.df.rolling(self.wins).max()) | ||
|
||
def time_rolling_min(self): | ||
(self.df.rolling(self.wins).min()) | ||
|
||
def time_rolling_std(self): | ||
(self.df.rolling(self.wins).std()) | ||
|
||
def time_rolling_count(self): | ||
(self.df.rolling(self.wins).count()) | ||
|
||
def time_rolling_skew(self): | ||
(self.df.rolling(self.wins).skew()) | ||
|
||
def time_rolling_kurt(self): | ||
(self.df.rolling(self.wins).kurt()) | ||
|
||
def time_rolling_sum(self): | ||
(self.df.rolling(self.wins).sum()) | ||
|
||
def time_rolling_corr(self): | ||
(self.dfs.rolling(self.wins).corr()) | ||
|
||
def time_rolling_cov(self): | ||
(self.dfs.rolling(self.wins).cov()) | ||
|
||
def time_rolling_quantile_0_l(self): | ||
(self.df.rolling(self.winl).quantile(0.0)) | ||
|
||
def time_rolling_quantile_1_l(self): | ||
(self.df.rolling(self.winl).quantile(1.0)) | ||
|
||
def time_rolling_quantile_median_l(self): | ||
(self.df.rolling(self.winl).quantile(0.5)) | ||
|
||
def time_rolling_median_l(self): | ||
(self.df.rolling(self.winl).median()) | ||
|
||
def time_rolling_median_l(self): | ||
(self.df.rolling(self.winl).mean()) | ||
|
||
def time_rolling_max_l(self): | ||
(self.df.rolling(self.winl).max()) | ||
|
||
def time_rolling_min_l(self): | ||
(self.df.rolling(self.winl).min()) | ||
|
||
def time_rolling_std_l(self): | ||
(self.df.rolling(self.wins).std()) | ||
|
||
def time_rolling_count_l(self): | ||
(self.df.rolling(self.wins).count()) | ||
|
||
def time_rolling_skew_l(self): | ||
(self.df.rolling(self.wins).skew()) | ||
|
||
def time_rolling_kurt_l(self): | ||
(self.df.rolling(self.wins).kurt()) | ||
|
||
def time_rolling_sum_l(self): | ||
(self.df.rolling(self.wins).sum()) | ||
|
||
|
||
class SeriesRolling(object): | ||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.N = 100000 | ||
self.Ns = 10000 | ||
self.df = pd.DataFrame({'a': np.random.random(self.N)}) | ||
self.dfs = pd.DataFrame({'a': np.random.random(self.Ns)}) | ||
self.sr = self.df.a | ||
self.srs = self.dfs.a | ||
self.wins = 10 | ||
self.winl = 1000 | ||
|
||
def time_rolling_quantile_0(self): | ||
(self.sr.rolling(self.wins).quantile(0.0)) | ||
|
||
def time_rolling_quantile_1(self): | ||
(self.sr.rolling(self.wins).quantile(1.0)) | ||
|
||
def time_rolling_quantile_median(self): | ||
(self.sr.rolling(self.wins).quantile(0.5)) | ||
|
||
def time_rolling_median(self): | ||
(self.sr.rolling(self.wins).median()) | ||
|
||
def time_rolling_median(self): | ||
(self.sr.rolling(self.wins).mean()) | ||
|
||
def time_rolling_max(self): | ||
(self.sr.rolling(self.wins).max()) | ||
|
||
def time_rolling_min(self): | ||
(self.sr.rolling(self.wins).min()) | ||
|
||
def time_rolling_std(self): | ||
(self.sr.rolling(self.wins).std()) | ||
|
||
def time_rolling_count(self): | ||
(self.sr.rolling(self.wins).count()) | ||
|
||
def time_rolling_skew(self): | ||
(self.sr.rolling(self.wins).skew()) | ||
|
||
def time_rolling_kurt(self): | ||
(self.sr.rolling(self.wins).kurt()) | ||
|
||
def time_rolling_sum(self): | ||
(self.sr.rolling(self.wins).sum()) | ||
|
||
def time_rolling_corr(self): | ||
(self.srs.rolling(self.wins).corr()) | ||
|
||
def time_rolling_cov(self): | ||
(self.srs.rolling(self.wins).cov()) | ||
|
||
def time_rolling_quantile_0_l(self): | ||
(self.sr.rolling(self.winl).quantile(0.0)) | ||
|
||
def time_rolling_quantile_1_l(self): | ||
(self.sr.rolling(self.winl).quantile(1.0)) | ||
|
||
def time_rolling_quantile_median_l(self): | ||
(self.sr.rolling(self.winl).quantile(0.5)) | ||
|
||
def time_rolling_median_l(self): | ||
(self.sr.rolling(self.winl).median()) | ||
|
||
def time_rolling_median_l(self): | ||
(self.sr.rolling(self.winl).mean()) | ||
|
||
def time_rolling_max_l(self): | ||
(self.sr.rolling(self.winl).max()) | ||
|
||
def time_rolling_min_l(self): | ||
(self.sr.rolling(self.winl).min()) | ||
|
||
def time_rolling_std_l(self): | ||
(self.sr.rolling(self.wins).std()) | ||
|
||
def time_rolling_count_l(self): | ||
(self.sr.rolling(self.wins).count()) | ||
|
||
def time_rolling_skew_l(self): | ||
(self.sr.rolling(self.wins).skew()) | ||
|
||
def time_rolling_kurt_l(self): | ||
(self.sr.rolling(self.wins).kurt()) | ||
|
||
def time_rolling_sum_l(self): | ||
(self.sr.rolling(self.wins).sum()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hadn't realized this before:
skiplist.get
is an O(log win) operation which we now have to perform twice. We also do askiplist.insert
and askiplist.remove
, which are also O(log win), and probably more expensive thanskiplist.get
, but a pessimistic estimation says the performance of this function will go down by 25%.I think there are two things to do here:
.get_two()
method toIndexableSkiplist
and use it here. I think that would be work for another PR, but creating an issue for tracking based on the results of the benchmarks should be part of merging this.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.
I ran some very simple performance tests. The new version is indeed 25% slower.
New
Old
YMMV, of course.
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.
Thanks for doing this! Seeing this, there is a more obvious approach to speeding this in a future PR: use the C implemented skiplist that median uses, instead of the Cython
IndexableSkiplist
used by quantile. But that's clearly a different PR.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.
@jaimefrio the issue is that for median you are only doing a single calculation. when doing many calculations (like here) a skip list is far faster. The actual impl of the skiplist could be improved a lot though (it has python objects inside it).