[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.
Reproducible example
data = {"a":[1]}
expr = (pl.col("a") - 0.5) / 1 * 1
pl.DataFrame(data).select(expr)["a"][0]
# 0.0 instead of 0.5
Log output
No response
Issue description
In the example provided above, the simple calculation of (1 - 0.5) / 1 * 1 produces the incorrect result of 0.0 instead of 0.5. Looking at the LazyFrame.explain, the cause seems to be an unexpected .cast(Int32) and the … / 1 is int and the … * 1.0 is float.
In more complex calculations, this can lead to incorrect numbers that seem correct because they're still in the right ballpark. I caught this with (18 - 10.5) / 2 * 15 which should be 56.25, but was 52.5.
Replacing pl.col("a") with pl.col("a").cast(float) fixes the issue.
Expected behavior
I'd expect all of these calculations to give the same result I'd get when typing the calculation in for each row. I'd also expect all of them to behave the same way.
Checks
Reproducible example
Log output
No response
Issue description
In the example provided above, the simple calculation of
(1 - 0.5) / 1 * 1
produces the incorrect result of0.0
instead of0.5
. Looking at theLazyFrame.explain
, the cause seems to be an unexpected.cast(Int32)
and the… / 1
is int and the… * 1.0
is float.Interestingly, very similar expressions give different results and don't seem to cast to int mid-expression.
In more complex calculations, this can lead to incorrect numbers that seem correct because they're still in the right ballpark. I caught this with
(18 - 10.5) / 2 * 15
which should be56.25
, but was52.5
.Replacing
pl.col("a")
withpl.col("a").cast(float)
fixes the issue.Expected behavior
I'd expect all of these calculations to give the same result I'd get when typing the calculation in for each row. I'd also expect all of them to behave the same way.
Installed versions