polars icon indicating copy to clipboard operation
polars copied to clipboard

Support `round` for Decimal type

Open Julian-J-S opened this issue 11 months ago • 0 comments

Description

Currently the decimal type does not suport round. Imo this makes sense to implement for many financial calculation where you require the precision of a decimal but in the end need to round to some fixed value.

from decimal import Decimal as D
import polars as pl

pl.DataFrame({"x": [D("0.246")]}).with_columns(r=pl.col("x").round(decimals=2))

# InvalidOperationError: `round` operation not supported for dtype `decimal[*,3]`

Currently I can only truncate the decimal for example with .cast(pl.Decimal(scale=2)) but this ofc does NOT round.

Julian-J-S avatar Mar 19 '24 09:03 Julian-J-S