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

Cast from `pl.Date` to `pl.Datetime` silently returns incorrect value when new dtype cannot hold value #16039

Open mcrumiller opened 2 weeks ago

mcrumiller commented 2 weeks ago

Checks

Reproducible example

When attempting to cast pl.Date to pl.Datetime("ns"), the date changes, when perhaps we should raise instead:

from datetime import date
import polars as pl

# lower date limit for nanosecond
pl.Series([date(1677, 9, 22)]).cast(pl.Datetime("ns")) # 1677-09-22 00:00:00
pl.Series([date(1677, 9, 21)]).cast(pl.Datetime("ns")) # 2262-04-11 23:34:33.709551616

# upper date limit for nanosecond
pl.Series([date(2262, 4, 11)]).cast(pl.Datetime("ns"))  # 2262-04-11 00:00:00
pl.Series([date(2262, 4, 12)]).cast(pl.Datetime("ns"))  # 1677-09-21 00:25:26.290448384

Installed versions

``` main ```
mcrumiller commented 2 weeks ago

@MarcoGorelli

MarcoGorelli commented 2 weeks ago

thanks for the ping