-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
single-element rolling_std returns 0 (rather than null) #11140
Comments
I believe this is related to #3717 Temporal windows just don't work correctly. |
not totally sure it's related to that one, I think the might just be a missing early return here - will take a look
I'd like to think the default case with n>0 rows should be quite robust, there's extensive hypothesis tests for those - we should probably extend all that testing to cover the rest of the params too note to future self: might need to look here: polars/crates/polars-arrow/src/legacy/kernels/rolling/no_nulls/variance.rs Lines 31 to 75 in 62f0929
|
ok found it, looks like it's currently hard-coded to return 0 in this case: polars/crates/polars-arrow/src/legacy/kernels/rolling/no_nulls/variance.rs Lines 118 to 125 in 62f0929
it'd be quite a refactor, but I think it probably should be if denom <= T::zero() {
None
} and then |
Interesting, the same thing happens in In [46]: df = pl.DataFrame({'ts': [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)], 'val': [1, 2, 3]}
...: ).sort('ts')
...:
...: print(df.select(pl.col('val').rolling_std('1d', by='ts', closed='right')))
...:
...: print(df.group_by_rolling('ts', period='1s', closed='right').agg(pl.col('val'), val_std=pl.col('val').std()))
shape: (3, 1)
┌─────┐
│ val │
│ --- │
│ f64 │
╞═════╡
│ 0.0 │
│ 0.0 │
│ 0.0 │
└─────┘
shape: (3, 3)
┌─────────────────────┬───────────┬─────────┐
│ ts ┆ val ┆ val_std │
│ --- ┆ --- ┆ --- │
│ datetime[μs] ┆ list[i64] ┆ f64 │
╞═════════════════════╪═══════════╪═════════╡
│ 2020-01-01 00:00:00 ┆ [1] ┆ 0.0 │
│ 2020-01-02 00:00:00 ┆ [2] ┆ 0.0 │
│ 2020-01-03 00:00:00 ┆ [3] ┆ 0.0 │
└─────────────────────┴───────────┴─────────┘ and there's tests that compare them, so they'll need fixing together |
Checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Reproducible example
Log output
No response
Issue description
The first example above returns
0
, the secondNone
Expected behavior
Both should return
None
?Noticed this while trying out #11134
Installed versions
The text was updated successfully, but these errors were encountered: