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

chore(rust): fix chrono deprecation warnings #14928

Merged
merged 2 commits into from
Mar 8, 2024
Merged

Conversation

orlp
Copy link
Collaborator

@orlp orlp commented Mar 8, 2024

@MarcoGorelli Could you check this out to make sure I didn't mess stuff up?

@github-actions github-actions bot added internal An internal refactor or improvement python Related to Python Polars rust Related to Rust Polars labels Mar 8, 2024
@orlp orlp changed the title chore: fix chrono deprecation warnings chore(rust): fix chrono deprecation warnings Mar 8, 2024
@orlp orlp removed the python Related to Python Polars label Mar 8, 2024
Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

nice!

Comment on lines -163 to +161
if v >= 0 {
NaiveDateTime::from_timestamp_opt(
// extract seconds from milliseconds
v / MILLISECONDS,
// discard extracted seconds and convert milliseconds to nanoseconds
(v % MILLISECONDS * MICROSECONDS) as u32,
)
} else {
let secs_rem = (v / MILLISECONDS, v % MILLISECONDS);
if secs_rem.1 == 0 {
// whole/integer seconds; no adjustment required
NaiveDateTime::from_timestamp_opt(secs_rem.0, 0)
} else {
// negative values with fractional seconds require 'div_floor' rounding behaviour.
// (which isn't yet stabilised: https://github.com/rust-lang/rust/issues/88581)
NaiveDateTime::from_timestamp_opt(
secs_rem.0 - 1,
(NANOSECONDS + (v % MILLISECONDS * MICROSECONDS)) as u32,
)
}
}
let delta = TimeDelta::try_milliseconds(v)?;
NaiveDateTime::UNIX_EPOCH.checked_add_signed(delta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

so satisfying 😍

Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 96.03960% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 81.03%. Comparing base (d9dead6) to head (82a7e4d).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/polars-arrow/src/temporal_conversions.rs 88.88% 2 Missing ⚠️
...lars-core/src/chunked_array/temporal/conversion.rs 80.00% 1 Missing ⚠️
crates/polars-plan/src/logical_plan/lit.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14928      +/-   ##
==========================================
+ Coverage   81.01%   81.03%   +0.01%     
==========================================
  Files        1332     1332              
  Lines      172870   172852      -18     
  Branches     2458     2458              
==========================================
+ Hits       140054   140066      +12     
+ Misses      32348    32317      -31     
- Partials      468      469       +1     

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

@ritchie46 ritchie46 merged commit 42a4b01 into pola-rs:main Mar 8, 2024
19 checks passed
@c-peters c-peters added the accepted Ready for implementation label Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation internal An internal refactor or improvement rust Related to Rust Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants