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: datetime operations (e.g. .dt.year) were raising when null values were backed by out-of-range integers #15420

Merged
merged 4 commits into from
Apr 1, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Apr 1, 2024

closes #15313

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Apr 1, 2024
@@ -151,7 +151,7 @@ pub fn timestamp_s_to_datetime_opt(seconds: i64) -> Option<NaiveDateTime> {
/// converts a `i64` representing a `timestamp(ms)` to [`NaiveDateTime`]
#[inline]
pub fn timestamp_ms_to_datetime(v: i64) -> NaiveDateTime {
timestamp_ms_to_datetime_opt(v).expect("invalid or out-of-range datetime")
timestamp_ms_to_datetime_opt(v).expect(&format!("invalid or out-of-range datetime: {v}"))
Copy link
Member

@ritchie46 ritchie46 Apr 1, 2024

Choose a reason for hiding this comment

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

Yikes. This does a heap allocation and string format for very function call. Which I expect are a lot.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry was just debugging 😄 when I saw what looked like np.NaT, I figured what the issue was

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i.e.:

In [3]: np.datetime64('NaT').astype('int64')
Out[3]: -9223372036854775808

@MarcoGorelli MarcoGorelli changed the title fix: datetime operations (e.g. .dt.year) were raising when null value… fix: datetime operations (e.g. .dt.year) were raising when null values were backed by out-of-range integers Apr 1, 2024
.iter()
.map(|v| v.map(|x| op(func(*x))))
.collect::<Vec<_>>(),
))
Copy link
Member

Choose a reason for hiding this comment

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

I believe you collect a Vec of options here and then create a PrimitiveArray. This will be a double allocation. You can create the array directly from the iterator.

Copy link

codecov bot commented Apr 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.13%. Comparing base (758b55a) to head (352b997).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15420   +/-   ##
=======================================
  Coverage   81.13%   81.13%           
=======================================
  Files        1362     1362           
  Lines      174802   174814   +12     
  Branches     2531     2531           
=======================================
+ Hits       141825   141836   +11     
  Misses      32493    32493           
- Partials      484      485    +1     

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

@ritchie46 ritchie46 merged commit 845e69b into pola-rs:main Apr 1, 2024
23 checks passed
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 rust Related to Rust Polars
Projects
None yet
2 participants