-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
fix(rust, python): include null count in rolling window validity with min_periods
#13863
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -190,15 +190,7 @@ fn test_rolling_map() { | |
|
||
assert_eq!( | ||
Vec::from(out), | ||
&[ | ||
None, | ||
None, | ||
Some(3.0), | ||
Some(3.0), | ||
Some(2.0), | ||
Some(5.0), | ||
Some(11.0) | ||
] | ||
&[None, None, Some(3.0), None, None, None, None,] | ||
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. This test was also previously incorrect. |
||
); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -21,6 +21,13 @@ def test_rolling_map_window_size_9160(input: list[int], output: list[int]) -> No | |
assert_series_equal(result, expected) | ||
|
||
|
||
def testing_rolling_map_window_size_with_nulls() -> None: | ||
s = pl.Series([0, 1, None, 3, 4, 5]) | ||
result = s.rolling_map(lambda x: sum(x), window_size=3, min_periods=3) | ||
expected = pl.Series([None, None, None, None, None, 12]) | ||
assert_series_equal(result, expected) | ||
|
||
|
||
def test_rolling_map_clear_reuse_series_state_10681() -> None: | ||
df = pl.DataFrame( | ||
{ | ||
|
@@ -86,7 +93,7 @@ def test_rolling_map_sum_int_cast_to_float() -> None: | |
function=lambda s: s.sum(), window_size=3, weights=[1.0, 2.0, 3.0] | ||
) | ||
|
||
expected = pl.Series("A", [None, None, 32.0, 20.0, 48.0], dtype=pl.Float64) | ||
expected = pl.Series("A", [None, None, 32.0, None, None], dtype=pl.Float64) | ||
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. This test was previously incorrect, as it did not take into account the null values in the window. |
||
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.
I realize that the null count is more efficiently calculated by only tracking the head and tail of each new window (i.e. decrementing if a null drops off and incrementing if a new null pops up), but because this is the slow
rolling_map
this is almost guaranteed not to be a bottleneck.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.
Nah.. Indeed. This might be the worst code in the repo. :(