-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Initial implementation of rolling iterators #27399
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
Closed
ThomasKluiters
wants to merge
28
commits into
pandas-dev:master
from
ThomasKluiters:rolling-iterator
Closed
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0cd558e
Initial implementation of rolling iterators
ThomasKluiters c33f2a4
Implement simple test cases
ThomasKluiters 285ebcc
Add whatsnew entry
ThomasKluiters 2d782c4
Fix Cython compile error
ThomasKluiters 4271782
Add expanding test cases
ThomasKluiters 68db60a
Implement date time index aware window
ThomasKluiters 3b10a49
Reformat
ThomasKluiters 525bdc6
Format window.pyx
ThomasKluiters c50a309
Fix failing tests
ee8f00e
Remove validate from iter
ThomasKluiters e1cf139
Merge branch 'master' of https://github.com/pandas-dev/pandas into ro…
ThomasKluiters 803a18f
Refactor get_window_indexer to _Window
ThomasKluiters 4c8adff
Merge branch 'master' of https://github.com/pandas-dev/pandas into ro…
ThomasKluiters 1252dfd
Merge branch 'rolling-iterator' of https://www.github.com/ThomasKluit…
ThomasKluiters e6eb230
Remove enumerate
ThomasKluiters 9833fa6
Add tests for min_periods
ThomasKluiters 0a2b416
Reformat tests
ThomasKluiters 6b559e9
Refactor tests
ThomasKluiters 62f0997
Implement support for nan values
ThomasKluiters 0d2d5b1
Rename duplicate test name
ThomasKluiters 412efa7
Use count() instead of roll_sum()
ThomasKluiters df5f199
Merge branch 'master' of https://github.com/pandas-dev/pandas into ro…
ThomasKluiters 285b5ba
Update create_blocks and _get_index
ThomasKluiters 33e24cb
Refactor tests into test_iterator
ThomasKluiters 4e2f1a2
Merge branch 'master' of https://github.com/pandas-dev/pandas into ro…
ThomasKluiters 755e0c1
Move whatsnew entry to 1.0.0
ThomasKluiters d58e897
Add iterators to computation.rst
ThomasKluiters e3b060c
Add issue #
ThomasKluiters 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -90,13 +90,62 @@ def test_missing_minp_zero(self): | |
expected = pd.Series([np.nan]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("klass", [pd.Series, pd.DataFrame]) | ||
def test_iter_raises(self, klass): | ||
# https://github.com/pandas-dev/pandas/issues/11704 | ||
# Iteration over a Window | ||
obj = klass([1, 2, 3, 4]) | ||
with pytest.raises(NotImplementedError): | ||
iter(obj.expanding(2)) | ||
@pytest.mark.parametrize( | ||
"dataframe,expected,window", | ||
[ | ||
( | ||
DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}), | ||
[({"A": [1, 2, 3], "B": [4, 5, 6]}, [0, 1, 2])], | ||
3, | ||
), | ||
( | ||
DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}), | ||
[ | ||
({"A": [1, 2], "B": [4, 5]}, [0, 1]), | ||
({"A": [1, 2, 3], "B": [4, 5, 6]}, [0, 1, 2]), | ||
], | ||
2, | ||
), | ||
( | ||
DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}), | ||
[ | ||
({"A": [1], "B": [4]}, [0]), | ||
({"A": [1, 2], "B": [4, 5]}, [0, 1]), | ||
({"A": [1, 2, 3], "B": [4, 5, 6]}, [0, 1, 2]), | ||
], | ||
1, | ||
), | ||
(DataFrame({"A": [1], "B": [4]}), [], 1337), | ||
(DataFrame(), [({}, [])], 1337), | ||
], | ||
) | ||
def test_iterator_dataframe(self, dataframe, expected, window): | ||
expected = [DataFrame(values, index=index) for (values, index) in expected] | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
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. can you add the issue number as a comment here |
||
|
||
for (expected, actual) in zip( | ||
expected, dataframe.expanding(min_periods=window) | ||
): | ||
tm.assert_frame_equal(actual, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"series,expected,window", | ||
[ | ||
(Series([1, 2, 3]), [([1, 2, 3], [0, 1, 2])], 3), | ||
(Series([1, 2, 3]), [([1, 2], [0, 1]), ([1, 2, 3], [0, 1, 2])], 2), | ||
( | ||
Series([1, 2, 3]), | ||
[([1], [0]), ([1, 2], [0, 1]), ([1, 2, 3], [0, 1, 2])], | ||
1, | ||
), | ||
(Series([1, 2]), [([1, 2], [0, 1])], 1337), | ||
(Series([]), [], 1337), | ||
], | ||
) | ||
def test_iterator_series(self, series, expected, window): | ||
expected = [Series(values, index=index) for (values, index) in expected] | ||
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 |
||
|
||
for (expected, actual) in zip(expected, series.expanding(min_periods=window)): | ||
tm.assert_series_equal(actual, expected) | ||
|
||
def test_expanding_axis(self, axis_frame): | ||
# see gh-23372. | ||
|
This file contains hidden or 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
This file contains hidden or 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
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.
move to 1.0 whatsnew
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.
also provide a reference to the new doc section.