polars
polars copied to clipboard
Initialize `Series` of `dtype=pl.Decimal` directly from list of python `int`s
Problem description
It would be nice to be able to do this:
numbers = [2963091539321097135000000000, 25658709114149718824803874]
pl.Series(numbers, dtype=pl.Decimal)
But doing so raises ComputeError: unable to convert any-value of dtype f64 to decimal
.
So instead it is necessary to manually convert to decimal first. Running pl.Config.activate_decimals()
does not remove the error
It looks an error only happens when using large int
s. This works without error:
numbers = [1, 2]
pl.Series(numbers, dtype=pl.Decimal)
This throws an error as Python has large integer support, but to interop with Rust it has to convert values > Int64 to Float64, which almost always guarantees a loss of precision - at which point you don't have the value you thought you had. I think it's reasonable to expect decimals as input here as the error prevents a worse scenario ;)
(Actually, I'll keep it open for now in case we can leverage i128
conversions in the future 🤔)