Closed CameronBieganek closed 3 months ago
It's because pl.len()
is unsigned.
>>> pl.select(pl.len(), overflow = pl.len() - 1)
shape: (1, 2)
┌─────┬────────────┐
│ len ┆ overflow │
│ --- ┆ --- │
│ u32 ┆ u32 │
╞═════╪════════════╡
│ 0 ┆ 4294967295 │
└─────┴────────────┘
Some previous regarding the general topic: https://github.com/pola-rs/polars/issues/11465
Ok, it's not clear to me if you are saying that 3 - pl.len()
is intentionally unsupported. If that's the case, I would say it is unexpected behavior for the average user, and definitely unergonomic. It can also lead to silently incorrect results, like the b_shift_bad
column above.
We are aware of the problem, there isn't a good solution yet as we cannot change types on runtime. We are aware of it and try to come up with a solution.
For now you can upcast your len to i64
.
pl.len().cast(pl.Int64)
.
I will close in favor of #11465
Checks
Reproducible example
Log output
No response
Issue description
-1 * (pl.len() - 3)
works as expected.3 - pl.len()
should work the same, but it does not.Expected behavior
The
b_shift_bad
column should be the same as theb_shift_good
column.Installed versions