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(rust, python): respect time_zone in lazy date_range #8591

Merged
merged 17 commits into from
Jul 2, 2023

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Apr 30, 2023

closes #8512

marking as draft while I split part of it out into a separate pr

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Apr 30, 2023
Comment on lines -138 to +170
DataType::Datetime(_, _) | DataType::Time => {
DataType::Datetime(tu, ref tz) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

separating the Datetime and Time arms to make use of tu and tz from Datetime

DateRange { .. } => return mapper.map_to_supertype(),
DateRange {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the output dtype may change according to tz, so need to do some extra computation here

Copy link
Member

Choose a reason for hiding this comment

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

Right, can you add that as comment?


let (tu, tz) = match dtype {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the output dtype isn't necessarily start.dtype() (if tz is not None). so instead of just recording tu and tz, I'm assigning to dtype, which contains tu and tz.

Then,

  • for Date, I just use Milliseconds as tu and None for tz
  • for Time, same, but with Nanoseconds as tu
  • for Datetime, use its tu and tz

start
.datetime()
.unwrap()
.replace_time_zone(None, None)?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if start and stop have a time zone, I'm removing it, as date_range_impl deals with that

@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 25, 2023 09:18
closed: _,
tz,
} => {
let mut ret = mapper.map_to_supertype()?;
Copy link
Member

Choose a reason for hiding this comment

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

Can we hoist this into a function. That keeps the schema branch a bit more lean.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup! by doing that, I realised that I hadn't quite done it correctly, and that it was wrong for (lazy) time_range too #9036

+1 for smaller functions and leaner logic, thanks!

DateRange { .. } => return mapper.map_to_supertype(),
DateRange {
Copy link
Member

Choose a reason for hiding this comment

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

Right, can you add that as comment?

@MarcoGorelli MarcoGorelli marked this pull request as draft May 25, 2023 10:53
@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 25, 2023 11:14
@MarcoGorelli MarcoGorelli marked this pull request as ready for review July 1, 2023 12:56
@MarcoGorelli MarcoGorelli marked this pull request as draft July 1, 2023 12:57
@MarcoGorelli MarcoGorelli marked this pull request as ready for review July 1, 2023 13:33
@ritchie46
Copy link
Member

Thanks for the reminder. Forgot about this one.

@ritchie46 ritchie46 merged commit 1686036 into pola-rs:main Jul 2, 2023
c-peters pushed a commit to c-peters/polars that referenced this pull request Jul 14, 2023
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
Development

Successfully merging this pull request may close these issues.

lazy date_range doesn't respect time zone
2 participants