polars
polars copied to clipboard
Decimals: string to decimal fails if more decimal places than "scale"
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.
Reproducible example
pl.DataFrame({
'x': ['1', '1.23', '1.2345'],
}).with_columns(
d=pl.col("x").cast(pl.Decimal(scale=2)),
)
Log output
ComputeError: conversion from `str` to `decimal[*,2]` failed in column 'x' for 1 out of 3 values: ["1.2345"]
Issue description
Converting from str to decimal fails if the str values contain more decimal places than the specified "scale" of the Decimal.
Expected behavior
This works in other libraries (e.g. pyspark) and should also work in polars. Also polars supports casting from f64 "1.2345" to Decimal "1.23"
pyspark:
Note: I am opening a lot of Decimal Issues (Decimals are required for many financial calculations where I currently use pyspark). I heard a bigger Decimal update in coming soon? Not sure abount the roadmap but happy to help.
Installed versions
0.20.5