-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Allow users to definite their own window bound calculations in rolling #29878
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
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
1c8c24a
Add BaseIndexer class
1188edd
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
6b5e894
Reformat Indexers
3a310f6
Remove init
d1d0775
Add BaseIndexer to api and allow rolling to accept BaseIndexer subcla…
218395e
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
46d4a52
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
c10854d
Lint cython files
c237090
Move indexers to pandas/core/window/indexers
1ddc828
Share get_window_bounds docstring
a861982
isort
8f482f7
Validate signature of get_window_bounds
38691c7
Validate signature of get_window_bounds
9d740d3
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
d18e954
Lint
f06e8e6
Comment on unused variables in calculate_variable_window_bounds
7ccbcd0
Type annotate _get_window_indexer & black
4e2fd30
self.index -> self.index_array
c3153d8
Add test for ExpandingIndexer
89100c4
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
2704c59
Add doc example in computation.rst with test + handle start, end boun…
87768ea
Add back win_type (for now)
6a6d896
Add 1.0.0 whatsnew note
2864e95
Remove BaseIndexers accepting win_type (weighted rolling)
b16e711
Lint
ed08ca3
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
9eb3022
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
f358466
Try changing import
0d8cc1f
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
25a05fe
Make doc example a code block, add docstring
5d8819f
Change self.__dict__(kwargs) to more explicit setattr
9194557
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
e7e1061
Fix docstring
09afec4
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
10c4994
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
9089f7b
Add BaseIndexer in doc/source/reference/window/rst
87e391f
Add typing for _validate_get_window_bounds_signature
7ce1967
Merge remote-tracking branch 'upstream/master' into feature/baseindexer
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -183,7 +183,8 @@ cdef inline void remove_sum(float64_t val, int64_t *nobs, float64_t *sum_x) nogi | |
|
||
|
||
def roll_sum_variable(ndarray[float64_t] values, ndarray[int64_t] start, | ||
ndarray[int64_t] end, int64_t minp): | ||
ndarray[int64_t] end, int64_t minp, | ||
bint is_monotonic_bounds=True): | ||
cdef: | ||
float64_t sum_x = 0 | ||
int64_t s, e | ||
|
@@ -198,11 +199,10 @@ def roll_sum_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
s = start[i] | ||
e = end[i] | ||
|
||
if i == 0: | ||
if i == 0 or not is_monotonic_bounds: | ||
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. could we do a simple calculcate in start/end to determine if is_monotonic is true here? it likely is quite performant. |
||
|
||
# setup | ||
sum_x = 0.0 | ||
nobs = 0 | ||
|
||
for j in range(s, e): | ||
add_sum(values[j], &nobs, &sum_x) | ||
|
||
|
@@ -218,6 +218,10 @@ def roll_sum_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
output[i] = calc_sum(minp, nobs, sum_x) | ||
|
||
if not is_monotonic_bounds: | ||
for j in range(s, e): | ||
remove_sum(values[j], &nobs, &sum_x) | ||
|
||
return output | ||
|
||
|
||
|
@@ -327,7 +331,8 @@ def roll_mean_fixed(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
|
||
def roll_mean_variable(ndarray[float64_t] values, ndarray[int64_t] start, | ||
ndarray[int64_t] end, int64_t minp): | ||
ndarray[int64_t] end, int64_t minp, | ||
bint is_monotonic_bounds=True): | ||
cdef: | ||
float64_t val, sum_x = 0 | ||
int64_t s, e | ||
|
@@ -342,11 +347,9 @@ def roll_mean_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
s = start[i] | ||
e = end[i] | ||
|
||
if i == 0: | ||
if i == 0 or not is_monotonic_bounds: | ||
|
||
# setup | ||
sum_x = 0.0 | ||
nobs = 0 | ||
for j in range(s, e): | ||
val = values[j] | ||
add_mean(val, &nobs, &sum_x, &neg_ct) | ||
|
@@ -365,6 +368,10 @@ def roll_mean_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
output[i] = calc_mean(minp, nobs, neg_ct, sum_x) | ||
|
||
if not is_monotonic_bounds: | ||
for j in range(s, e): | ||
val = values[j] | ||
remove_mean(val, &nobs, &sum_x, &neg_ct) | ||
return output | ||
|
||
# ---------------------------------------------------------------------- | ||
|
@@ -486,7 +493,8 @@ def roll_var_fixed(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
|
||
def roll_var_variable(ndarray[float64_t] values, ndarray[int64_t] start, | ||
ndarray[int64_t] end, int64_t minp, int ddof=1): | ||
ndarray[int64_t] end, int64_t minp, int ddof=1, | ||
bint is_monotonic_bounds=True): | ||
""" | ||
Numerically stable implementation using Welford's method. | ||
""" | ||
|
@@ -508,7 +516,7 @@ def roll_var_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
# Over the first window, observations can only be added | ||
# never removed | ||
if i == 0: | ||
if i == 0 or not is_monotonic_bounds: | ||
|
||
for j in range(s, e): | ||
add_var(values[j], &nobs, &mean_x, &ssqdm_x) | ||
|
@@ -528,6 +536,10 @@ def roll_var_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
output[i] = calc_var(minp, ddof, nobs, ssqdm_x) | ||
|
||
if not is_monotonic_bounds: | ||
for j in range(s, e): | ||
remove_var(values[j], &nobs, &mean_x, &ssqdm_x) | ||
|
||
return output | ||
|
||
# ---------------------------------------------------------------------- | ||
|
@@ -629,7 +641,8 @@ def roll_skew_fixed(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
|
||
def roll_skew_variable(ndarray[float64_t] values, ndarray[int64_t] start, | ||
ndarray[int64_t] end, int64_t minp): | ||
ndarray[int64_t] end, int64_t minp, | ||
bint is_monotonic_bounds=True): | ||
cdef: | ||
float64_t val, prev | ||
float64_t x = 0, xx = 0, xxx = 0 | ||
|
@@ -648,7 +661,7 @@ def roll_skew_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
# Over the first window, observations can only be added | ||
# never removed | ||
if i == 0: | ||
if i == 0 or not is_monotonic_bounds: | ||
|
||
for j in range(s, e): | ||
val = values[j] | ||
|
@@ -671,6 +684,11 @@ def roll_skew_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
output[i] = calc_skew(minp, nobs, x, xx, xxx) | ||
|
||
if not is_monotonic_bounds: | ||
for j in range(s, e): | ||
val = values[j] | ||
remove_skew(val, &nobs, &x, &xx, &xxx) | ||
|
||
return output | ||
|
||
# ---------------------------------------------------------------------- | ||
|
@@ -776,7 +794,8 @@ def roll_kurt_fixed(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
|
||
def roll_kurt_variable(ndarray[float64_t] values, ndarray[int64_t] start, | ||
ndarray[int64_t] end, int64_t minp): | ||
ndarray[int64_t] end, int64_t minp, | ||
bint is_monotonic_bounds=True): | ||
cdef: | ||
float64_t val, prev | ||
float64_t x = 0, xx = 0, xxx = 0, xxxx = 0 | ||
|
@@ -794,7 +813,7 @@ def roll_kurt_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
# Over the first window, observations can only be added | ||
# never removed | ||
if i == 0: | ||
if i == 0 or not is_monotonic_bounds: | ||
|
||
for j in range(s, e): | ||
add_kurt(values[j], &nobs, &x, &xx, &xxx, &xxxx) | ||
|
@@ -814,6 +833,10 @@ def roll_kurt_variable(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
output[i] = calc_kurt(minp, nobs, x, xx, xxx, xxxx) | ||
|
||
if not is_monotonic_bounds: | ||
for j in range(s, e): | ||
remove_kurt(values[j], &nobs, &x, &xx, &xxx, &xxxx) | ||
|
||
return output | ||
|
||
|
||
|
@@ -1007,7 +1030,8 @@ def roll_min_fixed(ndarray[float64_t] values, ndarray[int64_t] start, | |
|
||
|
||
def roll_min_variable(ndarray[float64_t] values, ndarray[int64_t] start, | ||
ndarray[int64_t] end, int64_t minp): | ||
ndarray[int64_t] end, int64_t minp, | ||
bint is_monotonic_bounds=True): | ||
""" | ||
Moving max of 1d array of any numeric type along axis=0 ignoring NaNs. | ||
|
||
|
@@ -1400,7 +1424,10 @@ def roll_generic_variable(object obj, | |
ndarray[int64_t] start, ndarray[int64_t] end, | ||
int64_t minp, | ||
int offset, object func, bint raw, | ||
object args, object kwargs): | ||
object args, object kwargs, | ||
bint is_monotonic_bounds=True): | ||
# is_monotonic_bounds unused since variable algorithm doesn't calculate | ||
# adds/subtracts across windows, but matches other *_variable functions | ||
cdef: | ||
ndarray[float64_t] output, counts, bufarr | ||
ndarray[float64_t, cast=True] arr | ||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.