-
-
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: Compute joint null mask before calling rolling corr/cov stats #18246
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,6 +589,36 @@ def test_rolling_cov_corr() -> None: | |
assert res["corr"][:2] == [None] * 2 | ||
|
||
|
||
def test_rolling_cov_corr_nulls() -> None: | ||
df1 = pl.DataFrame( | ||
{"a": [1.06, 1.07, 0.93, 0.78, 0.85], "lag_a": [1.0, 1.06, 1.07, 0.93, 0.78]} | ||
) | ||
df2 = pl.DataFrame( | ||
{ | ||
"a": [1.0, 1.06, 1.07, 0.93, 0.78, 0.85], | ||
"lag_a": [None, 1.0, 1.06, 1.07, 0.93, 0.78], | ||
} | ||
) | ||
|
||
val_1 = df1.select( | ||
pl.rolling_corr("a", "lag_a", window_size=10, min_periods=5, ddof=1).tail(1) | ||
).item() | ||
val_2 = df2.select( | ||
pl.rolling_corr("a", "lag_a", window_size=10, min_periods=5, ddof=1).tail(1) | ||
).item() | ||
|
||
assert val_1 == val_2 | ||
|
||
val_1 = df1.select( | ||
pl.rolling_cov("a", "lag_a", window_size=10, min_periods=5, ddof=1).tail(1) | ||
).item() | ||
val_2 = df2.select( | ||
pl.rolling_cov("a", "lag_a", window_size=10, min_periods=5, ddof=1).tail(1) | ||
).item() | ||
|
||
assert val_1 == val_2 | ||
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 also test the actual value here? 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. I changed the test as suggested and pushed. However, I also spent some time trying to put together a hypothesis test that would cross check these corr and cov functions against numpy. I could not get it to pass, and have an example frame which yields correlation > 1.0 :-/ df = pl.DataFrame( df_corr = df.select( I don't have time to push more on this right now (or even this week maybe). But I will log a separate issue. |
||
|
||
|
||
@pytest.mark.parametrize("time_unit", ["ms", "us", "ns"]) | ||
def test_rolling_empty_window_9406(time_unit: TimeUnit) -> None: | ||
datecol = pl.Series( | ||
|
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 also test the actual value here?