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: raise for out-of-range datetimes in to_datetime/strptime #13403

Merged
merged 2 commits into from
Jan 6, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Jan 3, 2024

closes #13401

currently logic:

  1. if the format follows a pattern known to not be supported (e.g. hour present but no minute), raise, see fix(rust, python): raise in to_datetime/strptime if format contains hour but not minute directive #9044 (this was meant to be temporary, but Why does chrono::NaiveDate::parse_from_str("2020-01-01 17", "%Y-%m-%d %H") pass? chronotope/chrono#1075 is still open)
  2. try parsing with NaiveDateTime
  3. if it errors, try NaiveDate

However, NaiveDate should only really be attempted instead of NaiveDateTime if parsing failed because there were too few arguments. So,

new logic:

  1. same as above (can't use parseerror.kind() there unfortunately, see linked PR)
  2. same as above
  3. only if it errors with kind NotEnough, then try NaiveDate

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jan 3, 2024
@MarcoGorelli MarcoGorelli marked this pull request as ready for review January 3, 2024 09:48
@ritchie46
Copy link
Member

same as above (can't use parseerror.kind() there unfortunately, see linked PR)

I don't follow? I see you using it. :P

@MarcoGorelli
Copy link
Collaborator Author

MarcoGorelli commented Jan 4, 2024

😄 it can be used to fix the linked issue, but not to get rid of the temporary workaround from #9044. See here for details: #8849 (comment)

(hoping it won't be temporary for too much longer...)

@ritchie46 ritchie46 merged commit f54e7a7 into pola-rs:main Jan 6, 2024
25 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
Development

Successfully merging this pull request may close these issues.

to_datetime may give incorrect results if time part is wrong
2 participants