-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
TST: add test for rolling max/min/mean with DatetimeIndex over different frequencies #29932
Merged
WillAyd
merged 6 commits into
pandas-dev:master
from
ganevgv:tests/test_rolling_max_datetimeindex
Dec 1, 2019
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7852918
add test for rolling max with DatetimeIndex
ganevgv 041df3f
move and simplify test
ganevgv a4729b2
parametrize over freqs and ops
ganevgv 441f4f2
Merge remote-tracking branch 'upstream/master' into tests/test_rollin…
ganevgv eb58e54
use f-string
ganevgv f13216f
passes black
ganevgv 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 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 |
---|---|---|
|
@@ -535,15 +535,36 @@ def test_ragged_max(self): | |
expected["B"] = [0.0, 1, 2, 3, 4] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_minutes_freq_max(self): | ||
@pytest.mark.parametrize( | ||
"freq, op, result_data", | ||
[ | ||
("ms", "min", [0.0] * 10), | ||
("ms", "mean", [0.0] * 9 + [2.0 / 9]), | ||
("ms", "max", [0.0] * 9 + [2.0]), | ||
("s", "min", [0.0] * 10), | ||
("s", "mean", [0.0] * 9 + [2.0 / 9]), | ||
("s", "max", [0.0] * 9 + [2.0]), | ||
("min", "min", [0.0] * 10), | ||
("min", "mean", [0.0] * 9 + [2.0 / 9]), | ||
("min", "max", [0.0] * 9 + [2.0]), | ||
("h", "min", [0.0] * 10), | ||
("h", "mean", [0.0] * 9 + [2.0 / 9]), | ||
("h", "max", [0.0] * 9 + [2.0]), | ||
("D", "min", [0.0] * 10), | ||
("D", "mean", [0.0] * 9 + [2.0 / 9]), | ||
("D", "max", [0.0] * 9 + [2.0]), | ||
], | ||
) | ||
def test_freqs_ops(self, freq, op, result_data): | ||
# GH 21096 | ||
n = 10 | ||
index = date_range(start="2018-1-1 01:00:00", freq="1min", periods=n) | ||
index = date_range( | ||
start="2018-1-1 01:00:00", freq="1{}".format(freq), periods=10 | ||
) | ||
s = Series(data=0, index=index) | ||
s.iloc[1] = np.nan | ||
s.iloc[-1] = 2 | ||
result = s.rolling(window=f"{n}min").max() | ||
expected = Series(data=[0] * (n - 1) + [2.0], index=index) | ||
result = getattr(s.rolling(window="10{}".format(freq)), op)() | ||
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. Same comment 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. done |
||
expected = Series(data=result_data, index=index) | ||
|
||
tm.assert_series_equal(result, expected) | ||
|
||
|
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.
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 use f-string instead of .format?
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.
good note - done