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

fix(python): Convert date and datetime in literal construction #16018

Open mcrumiller opened 2 weeks ago

mcrumiller commented 2 weeks ago

Fixes #16012.

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 81.33%. Comparing base (42795c6) to head (e717464). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #16018 +/- ## ========================================== + Coverage 80.75% 81.33% +0.57% ========================================== Files 1393 1403 +10 Lines 179459 183308 +3849 Branches 2924 2928 +4 ========================================== + Hits 144929 149089 +4160 + Misses 34027 33716 -311 Partials 503 503 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mcrumiller commented 2 weeks ago

@alexander-beedie thanks, working on parametrizing and indeed running into cases where we're outside the Datetime casting ability, but I'm not sure how to deal with it. It looks like Date.cast(Datetime) fails (may open an issue) in general (@MarcoGorelli) (opened #16039):

from datetime import date
import polars as pl

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
mcrumiller commented 2 weeks ago

@alexander-beedie fixed up a few things and expanded the tests. Let me know if you think it needs more testing or changes.

I restricted the times in the test to be within the Date -> Nanosecond allowance, as that can be addressed in the other issue I opened.

alexander-beedie commented 12 hours ago

Sorry, let this one sit; can you rebase/update and I'll take another look :)

mcrumiller commented 34 minutes ago

@alexander-beedie should be good once tests complete.