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

feat: Always preserve sorted flag for .dt.date #18692

Merged
merged 3 commits into from
Sep 15, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

No description provided.

Comment on lines 274 to 280
DataType::Datetime(tu, Some(tz)) => {
let mut out = {
polars_ops::chunked_array::replace_time_zone(
s.datetime().unwrap(),
None,
&StringChunked::from_iter(std::iter::once("raise")),
NonExistent::Raise,
)?
.cast(&DataType::Datetime(*tu, None))?
};
if tz != "UTC" {
// DST transitions may not preserve sortedness.
out.set_sorted_flag(IsSorted::Not);
}
Ok(out)
},
DataType::Datetime(tu, Some(_)) => polars_ops::chunked_array::replace_time_zone(
s.datetime().unwrap(),
None,
&StringChunked::from_iter(std::iter::once("raise")),
NonExistent::Raise,
)?
.cast(&DataType::Datetime(*tu, None)),
Copy link
Collaborator Author

@MarcoGorelli MarcoGorelli Sep 11, 2024

Choose a reason for hiding this comment

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

polars_ops::chunked_array::replace_time_zone already deals with unsetting the sortedness flag if necessary, so this can now be simplified

there's already tests which check sortedness for replacing the time zone:

  • test_replace_time_zone_sortedness_series
  • test_replace_time_zone_sortedness_expressions

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.87%. Comparing base (962b576) to head (06f1949).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18692      +/-   ##
==========================================
+ Coverage   79.86%   79.87%   +0.01%     
==========================================
  Files        1517     1517              
  Lines      205542   205532      -10     
  Branches     2892     2892              
==========================================
+ Hits       164156   164173      +17     
+ Misses      40838    40811      -27     
  Partials      548      548              

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

@MarcoGorelli MarcoGorelli changed the title feat: always preserve sorted flag for .dt.date feat: Always preserve sorted flag for .dt.date Sep 12, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Sep 12, 2024
@MarcoGorelli MarcoGorelli marked this pull request as ready for review September 12, 2024 08:35
Comment on lines -1378 to +1377
pl.Series("ts", [1603584000000000, 1603587600000000])
pl.Series("ts", [1603584000000001, 1603587600000000])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@orlp I think this is what you were asking for? like this, the example shows why the sorted flag shouldn't be preserved for 'Europe/London'

@ritchie46
Copy link
Member

Can you rebase?

@ritchie46 ritchie46 merged commit 5a262db into pola-rs:main Sep 15, 2024
26 checks passed
nameexhaustion pushed a commit to nameexhaustion/polars that referenced this pull request Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants