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

Implement min, max, sum and mean of Rolling in Series and DataFrame #996

Merged
merged 7 commits into from Nov 7, 2019

Conversation

itholic
Copy link
Contributor

@itholic itholic commented Nov 3, 2019

This PR implement min, max, sum and mean of Rolling in Series and DataFrame

For Series:

>>> kser = ks.Series([2, 3, float("nan"), 10])
>>> kser
0     2.0
1     3.0
2     NaN
3    10.0
Name: 0, dtype: float64

>>> ksr.rolling(2).sum()
0    NaN
1    5.0
2    3.0
3    NaN
Name: 0, dtype: float64

>>> ks.rolling(2).min()
0    NaN
1    2.0
2    3.0
3    NaN
Name: 0, dtype: float64

>>> ks.rolling(2).max()
0    NaN
1    3.0
2    3.0
3    NaN
Name: 0, dtype: float64

>>> ks.rolling(2).mean()
0    NaN
1    2.5
2    3.0
3    NaN
Name: 0, dtype: float64

For DataFrame

>>> kdf = ks.DataFrame({'a': [1, float('nan'), 3], 'b': [1.0, 2.0, 3.0]})
>>> kdf
     a    b
0  1.0  1.0
1  NaN  2.0
2  3.0  3.0

>>> kdf.rolling(2).sum()
     a    b
0  NaN  NaN
1  1.0  3.0
2  NaN  5.0

>>> kdf.rolling(2).min()
     a    b
0  NaN  NaN
1  1.0  1.0
2  NaN  2.0

>>> kdf.rolling(2).max()
     a    b
0  NaN  NaN
1  1.0  2.0
2  NaN  3.0

>>> kdf.rolling(2).mean()
     a    b
0  NaN  NaN
1  1.0  1.5
2  NaN  2.5

relates to #977

@codecov-io
Copy link

codecov-io commented Nov 3, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@9434e48). Click here to learn what that means.
The diff coverage is 86.2%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #996   +/-   ##
=========================================
  Coverage          ?   92.46%           
=========================================
  Files             ?       34           
  Lines             ?     6698           
  Branches          ?        0           
=========================================
  Hits              ?     6193           
  Misses            ?      505           
  Partials          ?        0
Impacted Files Coverage Δ
databricks/koalas/generic.py 95.73% <ø> (ø)
databricks/koalas/window.py 93.03% <86.2%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9434e48...364254c. Read the comment docs.

4 13.0 65.0
"""
def sum(scol):
window = Window.orderBy(self._index_scols)
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this into _apply_as_series_or_frame and use self._window? We can match the implementation into Expanding one I think.

Copy link
Contributor Author

@itholic itholic Nov 6, 2019

Choose a reason for hiding this comment

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

@HyukjinKwon
Thanks for the comment!

but maybe is it possible although this window and self._window are used for different purpose like below?

스크린샷 2019-11-06 오후 3 18 34

i think to calculate F.lag(scol, self._window_val).over(window) >= self._min_periods, we need another window rather than self._window

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

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

Looks fine otherwise.

@HyukjinKwon
Copy link
Member

@itholic can you rebase please?

@itholic
Copy link
Contributor Author

itholic commented Nov 7, 2019

@HyukjinKwon sure, i just did.

@softagram-bot
Copy link

Softagram Impact Report for pull/996 (head commit: 364254c)

⭐ Change Overview

Showing the changed files, dependency changes and the impact - click for full size
(Open in Softagram Desktop for full details)

📄 Full report

Impact Report explained. Give feedback on this report to support@softagram.com

@HyukjinKwon
Copy link
Member

Let me clean up by myself. merged

@HyukjinKwon HyukjinKwon merged commit 21cff0f into databricks:master Nov 7, 2019
@itholic
Copy link
Contributor Author

itholic commented Nov 8, 2019

@HyukjinKwon Thanks :)

@itholic itholic deleted the rolling_sum_min_max_mean branch November 8, 2019 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants