-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Poisson exponential window #26243
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
Conversation
pandas/core/window.py
Outdated
'slepian': ['width']} | ||
'slepian': ['width'], | ||
'exponential': ['center', 'tau']} | ||
immutable_args_map = {'exponential': {'center': None}} |
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.
this map is here because window
param in get_window
function (https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.signal.get_window.html) for exponential window (https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.signal.exponential.html#scipy.signal.exponential) needs parameters center
and tau
. But we do not want to set center
here.
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.
Not sure I completely follow - do you have a test case that is supposed to hit 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 will try to describe it more deeply. Maybe we will find a better solution.
Window is created by calling sig.get_window
(
Line 655 in 3876dd8
return sig.get_window(win_type, window, False).astype(float) |
win_type
that consists of few items (win_name, win_param_1, win_param_2, ...) - it was already implemented and works perfectly for previously supproted windows.For example for gaussinan window, you have to call scipy function
sig.get_window
like this w = sig.get_window(("gaussian", 1), N, True)
. The tuple ("gaussian", 1)
is inside scipy.singal
parsed and appropriate function is then called e.g. here for gaussian is called scipy.signal.gaussian(M, std, sym=True)
-> scipy.signal.gaussian(N, 1)
The exponential window is defined like this scipy.signal.exponential(M, center=None, tau=1.0, sym=True)
, and the problem is in center
parameter. I need to prepare win_type
(the tuple) that contains None
as the first window parameter, but is not user parameter passed in kwargs (and should not be). So for exponential window, I need the tuple like this ('exponential', None, tau). This is the main complexity here that I need to add aditional param that is not passed by user in kwargs.
About the test. The immutable_args_map
functionality is tested when test_cmov_window_special
is called for exponential window.
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.
Hmm...it feels somewhat special-case-y, but this seems to be borne out of scipy
API. I don't feel great about this, but I do understand the necessity.
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 checked all possible windows in scipy once again and I did not find another window, where we would use this approach. For other windows (if they will be in future implemented), the parameters exposed in pandas will be the same as the ones passed to underlying scipy function sig.get_window()
. So maybe this immutable_args_map
is overkill here. I will try to come another (more lightweight) solution.
Codecov Report
@@ Coverage Diff @@
## master #26243 +/- ##
==========================================
- Coverage 91.97% 91.96% -0.01%
==========================================
Files 175 175
Lines 52368 52373 +5
==========================================
+ Hits 48164 48166 +2
- Misses 4204 4207 +3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26243 +/- ##
==========================================
- Coverage 91.98% 91.98% -0.01%
==========================================
Files 175 175
Lines 52374 52380 +6
==========================================
+ Hits 48178 48182 +4
- Misses 4196 4198 +2
Continue to review full report at Codecov.
|
pandas/core/window.py
Outdated
'slepian': ['width']} | ||
'slepian': ['width'], | ||
'exponential': ['center', 'tau']} | ||
immutable_args_map = {'exponential': {'center': None}} |
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.
Not sure I completely follow - do you have a test case that is supposed to hit this?
'slepian': ['width'], | ||
'exponential': ['center', 'tau']} | ||
immutable_args_map = {'exponential': {'center': None}} | ||
|
||
if win_type in arg_map: |
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.
why are you changing the structure of passing args here? was there some reason the existing would not just work?
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.
For exponential window kwargs contains {tau: 10}
but I need to get back tuple (None, 10)
(first None
is the center parameter required for exponential window). So I pass the immutable_args
to _pop_args
function that is the second source of params (another than kwargs).
Another possible option can be add {"center": None} to kwargs for exponential window and let _pop_args
without change.
More info about exponential window is in comments above.
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.
yes pls do this instead
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.
The code is now without immutable_args
. As I wrote in another comment, I simplyfied my code even more because other window (that would be possibly implemented in future) in scipy will not need such handling like the exponential one. So please check the last code version.
Thanks.
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.
Last commit looks a lot better so thanks! Just as a general question, is there no need whatsoever for a user to pass center
through kwargs? Seems like this one-off handling might prevent that from going through if there's a legitimate use for it?
Yes, user cannot pass Line 644 in 48ea04f
False - that means that this function creates symetric window. For exponential window (https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.signal.exponential.html), if you set sym=True , you cannot set center param (its in documentation)
|
'slepian': ['width'], | ||
'exponential': ['center', 'tau']} | ||
immutable_args_map = {'exponential': {'center': None}} | ||
|
||
if win_type in arg_map: |
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.
yes pls do this instead
also a conflict in 0.25.0 whatsnew |
33e59e7
to
d867ad4
Compare
Rebased, conflict solved |
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.
lgtm. can you also update the docs: http://pandas-docs.github.io/pandas-docs-travis/user_guide/computation.html#window-functions (at the end of the section)
Updated. |
thanks @rbenes |
git diff upstream/master -u -- "*.py" | flake8 --diff