[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
import polars as pl
v = Decimal("99999.99999999999999999999")
s = pl.Series([v])
result = s.cast(pl.Decimal(25, 20))
print(result)
Log output
Traceback (most recent call last):
File "/home/stijn/code/polars/py-polars/repro.py", line 22, in <module>
s = pl.Series([v], dtype=pl.Decimal(25, 20))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/stijn/code/polars/py-polars/polars/series/series.py", line 312, in __init__
self._s = sequence_to_pyseries(
^^^^^^^^^^^^^^^^^^^^^
File "/home/stijn/code/polars/py-polars/polars/_utils/construction/series.py", line 152, in sequence_to_pyseries
pyseries = pyseries.cast(dtype, strict=strict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ComputeError: conversion from `decimal[*,20]` to `decimal[25,20]` failed in column '' for 1 out of 1 values: [99999.99999999999999999999]
Issue description
The decimal number has 25 places (5 before / 20 after the decimal point). Casting to precision 25 should work. Casting to precision 26 does work, however.
This issue does not occur with lower precision numbers:
import polars as pl
v = Decimal("99999.99999")
s = pl.Series([v], dtype=pl.Decimal(10, 5))
print(s) # works
Checks
Reproducible example
Log output
Issue description
The decimal number has 25 places (5 before / 20 after the decimal point). Casting to precision 25 should work. Casting to precision 26 does work, however.
This issue does not occur with lower precision numbers:
Expected behavior
No error.
Installed versions
main