Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

mcrumiller
Copy link
Contributor

Fixes #16012.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels May 2, 2024
@mcrumiller mcrumiller force-pushed the lit-date-datetime branch 2 times, most recently from 598ca60 to 22992c8 Compare May 2, 2024 14:25
@mcrumiller mcrumiller marked this pull request as ready for review May 2, 2024 14:44
Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.73%. Comparing base (120ec7f) to head (7fe2e2d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16018   +/-   ##
=======================================
  Coverage   80.72%   80.73%           
=======================================
  Files        1475     1475           
  Lines      193337   193351   +14     
  Branches     2760     2764    +4     
=======================================
+ Hits       156079   156101   +22     
+ Misses      36748    36740    -8     
  Partials      510      510           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@alexander-beedie alexander-beedie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tweak the unit tests to include a wider range of dates/datetimes (including pre-epoch, etc)? 👍

@mcrumiller
Copy link
Contributor Author

mcrumiller commented May 3, 2024

@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
Copy link
Contributor Author

@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
Copy link
Collaborator

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

@mcrumiller
Copy link
Contributor Author

@alexander-beedie should be good once tests complete.

@mcrumiller
Copy link
Contributor Author

Hey @alexander-beedie wanna merge this one before it goes stale again?

@alexander-beedie
Copy link
Collaborator

Hey @alexander-beedie wanna merge this one before it goes stale again?

Oops! Will look shortly 👍

@mcrumiller mcrumiller force-pushed the lit-date-datetime branch 2 times, most recently from 6eb4bd5 to 7fe2e2d Compare July 1, 2024 13:11
@mcrumiller
Copy link
Contributor Author

@alexander-beedie rebased again.

@mcrumiller
Copy link
Contributor Author

Hey @alexander-beedie this one's gone stale again and it's not too complex.

py-polars/polars/functions/lit.py Outdated Show resolved Hide resolved
py-polars/polars/functions/lit.py Outdated Show resolved Hide resolved
py-polars/polars/functions/lit.py Outdated Show resolved Hide resolved
@alexander-beedie
Copy link
Collaborator

Hey @alexander-beedie this one's gone stale again and it's not too complex.

Shame on me! 😅
A few comments, then it's likely good to go.

@mcrumiller mcrumiller marked this pull request as draft August 15, 2024 14:49
@mcrumiller mcrumiller marked this pull request as ready for review August 15, 2024 15:34
@mcrumiller
Copy link
Contributor Author

mcrumiller commented Aug 15, 2024

Test failure due to #18211, unrelated to this PR.

@alexander-beedie I think this is ready to go now.

@alexander-beedie alexander-beedie merged commit 5e5506c into pola-rs:main Aug 15, 2024
16 of 18 checks passed
@mcrumiller mcrumiller deleted the lit-date-datetime branch August 15, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dtype ingored in pl.lit between date and datetime
2 participants