Skip to content

Commit e8e0295

Browse files
authored
fix: Fix Expr.over applying scale incorrectly for Decimal types (#21140)
1 parent f1f3775 commit e8e0295

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

crates/polars-expr/src/expressions/window.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ fn set_by_groups(
699699
}};
700700
}
701701
downcast_as_macro_arg_physical!(&s, dispatch)
702-
.map(|s| s.cast(dtype).unwrap())
702+
.map(|s| unsafe { s.from_physical_unchecked(dtype) }.unwrap())
703703
.map(Column::from)
704704
} else {
705705
None

py-polars/tests/unit/datatypes/test_decimal.py

+6
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,9 @@ def test_cast_float_to_decimal_12775() -> None:
712712
# default scale = 0
713713
assert s.cast(pl.Decimal).to_list() == [D("1")]
714714
assert s.cast(pl.Decimal(scale=1)).to_list() == [D("1.5")]
715+
716+
717+
def test_decimal_min_over_21096() -> None:
718+
df = pl.Series("x", [1, 2], pl.Decimal(scale=2)).to_frame()
719+
result = df.select(pl.col("x").min().over("x"))
720+
assert result["x"].to_list() == [D("1.00"), D("2.00")]

0 commit comments

Comments
 (0)