Skip to content
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

Merged
merged 54 commits into from
Jul 6, 2020

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke commented Jun 17, 2020

  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

This enhancement allows EWMA to be calculated relative to the timestamp in which an observation occurs instead of assuming each observation is equally spaced.

@pep8speaks
Copy link

pep8speaks commented Jun 17, 2020

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

@mroeschke mroeschke added Enhancement Window rolling, ewma, expanding labels Jun 17, 2020
@mroeschke mroeschke changed the title WIP: ENH: Add support for calculating EWMA with a time component ENH: Add support for calculating EWMA with a time component Jun 21, 2020
@mroeschke mroeschke added this to the 1.1 milestone Jun 26, 2020

last_result = vals[0]

for i in range(N):
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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

tm.assert_frame_equal(result, expected)


def test_ewma_with_times_variable_spacing():
Copy link
Contributor

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)

@jreback
Copy link
Contributor

jreback commented Jun 29, 2020

cc @pandas-dev/pandas-core if anyone has comments.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jreback jreback merged commit 7e9f66e into pandas-dev:master Jul 6, 2020
@jreback
Copy link
Contributor

jreback commented Jul 6, 2020

thanks @mroeschke

@mroeschke mroeschke deleted the time_ewma branch July 7, 2020 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants