pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
26.63k stars 1.63k forks source link

Casting float to Decimal fails silently #16047

Closed stinodego closed 1 week ago

stinodego commented 1 week ago

Checks

Reproducible example

import polars as pl

s = pl.Series([0.1]).cast(pl.Decimal(10, 5))
print(s)

Log output

shape: (1,)
Series: '' [f64]
[
        0.1
]

Issue description

The cast doesn't work and the dtype remains a float. No error is thrown.

Expected behavior

This cast should work.

Installed versions

main

JulianCologne commented 1 week ago

yeah, I have a very similar issue already (#12775)

It actually works if you "activate the Decimal"

pl.Config.activate_decimals(True)

pl.Series([0.1]).cast(pl.Decimal(10, 5))

shape: (1,)
Series: '' [decimal[10,5]]
[
    0.10000
]

However, there is still a "bug" where the precision is not correctly inferred

pl.Series([5.67]).cast(pl.Decimal)

shape: (1,)
Series: '' [decimal[38,0]]
[
    5
]
stinodego commented 1 week ago

Thanks for the link - closing this one then!