pola-rs / polars

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

panic when returning dates larger than datetime.date can handle #8632

Open mcrumiller opened 1 year ago

mcrumiller commented 1 year ago

Polars version checks

Issue description

This is running into weird edge-case territory, but if you use polars to create a date that surpasses datetime.date's limits, we get a panic when trying to retrieve the underlying date.

Reproducible example

from datetime import date
import polars as pl

# create a series that's 1 day more than datetime.date can handle. Polars does fine with it.
s = pl.Series([date(9999, 12, 31)]).dt.offset_by("1d")

# panic here:
s.item() 
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'OverflowError'>,
value: OverflowError('date value out of range'), traceback: Some(<traceback object at 0x00000205D798AF40>) }

Expected behavior

Should raise error or not allow this behavior.

Installed versions

``` ---Version info--- Polars: 0.17.11 Index type: UInt32 Platform: Windows-10-10.0.19044-SP0 Python: 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] ---Optional dependencies--- numpy: 1.24.2 pandas: 2.0.1 pyarrow: 11.0.0 connectorx: 0.3.2_alpha.2 deltalake: fsspec: matplotlib: 3.7.1 xlsx2csv: 0.8.1 xlsxwriter: 3.0.9 ```
stinodego commented 9 months ago

This is not an easy fix, as the IntoPy trait defines the into_py method without a Result type. So we have to unwrap the call to _to_python_date.