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): read_csv was parsing dates incorrectly when the dtype was overridden #9420

Merged
merged 3 commits into from
Jun 18, 2023

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Jun 17, 2023

closes #9102

The main idea here is:

  • instead of using try_from(pattern), use try_from_with_unit(pattern, unit)

Then, instead of having to do

infer = try_from(pattern);
infer.transform = match time_unit {
    ...
}

you can just do

infer = try_from_with_unit(pattern, time_unit);

It also means you can pass the time_unit forwards within the slow_datetime_parser

To get the time_unit, it needs to be an argument of parse_bytes. I've made it of type Option<TimeUnit>, so that when parsing non-datetime type (e.g. Utf8), then time_unit can be set to None, and for datetime, it can either be the default Microsecond or whatever the user overrid it with

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jun 17, 2023
@MarcoGorelli MarcoGorelli marked this pull request as ready for review June 17, 2023 20:18
{
let val = match value {
Value::String(s) => s,
_ => return None,
};
infer_pattern_single(val).and_then(|pattern| {
match DatetimeInfer::<T::Native>::try_from(pattern) {
match DatetimeInfer::<T::Native>::try_from_with_unit(pattern, Some(TimeUnit::Microseconds))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just preserving the status-quo here, but perhaps this could also be more precise - will take a look

Copy link
Member

@ritchie46 ritchie46 left a comment

Choose a reason for hiding this comment

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

Looks good @MarcoGorelli. Thanks!

Can be merged when the conflicts are solved.

@MarcoGorelli
Copy link
Collaborator Author

thanks for your review! ok shipping then

@MarcoGorelli MarcoGorelli merged commit ff2a97e into pola-rs:main Jun 18, 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.

Issues parsing nanosecond Datetimes
2 participants