polars
polars copied to clipboard
Multiplication by const raises `(left == right)` assert exception
Polars version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of Polars.
Issue description
When filtering a colum in agg expression and after filtering we have 0 values, diff + multiplication may raise
pyo3_runtime.PanicException: assertion failed: `(left == right)`
left: `0`,
right: `1`.
Note that if we moved * 1000 all works as expected:
pl.DataFrame({'col_to_groupby': [2], 'time': [1672740910.967138], 'col3': [1]}).groupby('col_to_groupby').agg(
(pl.col('time').filter(pl.col('col3') == 0).diff().fill_null(strategy='zero')
.diff().fill_null(strategy='zero') * 1000).mean().alias('fwd_iat_ho_mean').alias('calc')
)
Reproducible example
import polars as pl
pl.DataFrame({'col_to_groupby': [2], 'time': [1672740910.967138], 'col3': [1]}).groupby('col_to_groupby').agg(
(pl.col('time').filter(pl.col('col3') == 0).diff() * 1000).fill_null(strategy='zero')
.diff().fill_null(strategy='zero').mean().alias('calc')
)
pyo3_runtime.PanicException: assertion failed: `(left == right)`
left: `0`,
right: `1`
Expected behavior
Computation should return:
| col_to_groupby | calc |
|---|---|
| i64 | f64 |
| 2 | null |
Installed versions
---Version info---
Polars: 0.15.11
Index type: UInt32
Platform: Linux-5.15.0-56-generic-x86_64-with-glibc2.35
Python: 3.8.16 (default, Dec 7 2022, 01:12:06)
[GCC 11.3.0]
---Optional dependencies---
pyarrow: 10.0.1
pandas: <not installed>
numpy: 1.22.3
fsspec: 2022.8.2
connectorx: <not installed>
xlsx2csv: <not installed>
matplotlib: <not installed>
None