-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ENH: Add support for calculating EWMA with a time component #34839
Conversation
Hello @mroeschke! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-07-06 21:33:14 UTC |
|
||
last_result = vals[0] | ||
|
||
for i in range(N): |
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.
can you you put this in a nogil block? do we have timings on 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 tried to nogil
this but could not since we are doing array arithmetic & broadcasting.
weights = 0.5 ** ((times[i] - times[mask.view(np.bool_)]) / halflife)
observations = vals[mask.view(np.bool_)]
last_result = np.sum(weights * observations) / np.sum(weights)
I can add an ASV for 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.
ok sure on the asv.
I think you can convert the mask view to a np.take operation (but can always just add an issue for this) if needed
pandas/tests/window/test_ewm.py
Outdated
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_ewma_with_times_variable_spacing(): |
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.
can you add an example that has times in DTI w/tz (I think answer should be the same as naive but just checking)
cc @pandas-dev/pandas-core if anyone has comments. |
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
thanks @mroeschke |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
This enhancement allows EWMA to be calculated relative to the timestamp in which an observation occurs instead of assuming each observation is equally spaced.