-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Ability to control the assumed century cutoff with Expr.str.to_date
when parsing 2-digit years
#17213
Comments
If such a thing were added it should definitely be explicit rather than something stashed invisibly in the |
First assumption was that it is not on polars but on chrono (rust date/datetime parser) but chrono seems to be "fine" fn main() {
use chrono::NaiveDate; // 0.4.38
let Y_M_D = "%y-%m-%d";
let D_M_Y = "%d-%m-%y";
let Y_M_D_Text = ["49-01-01", "49-12-31", "50-01-01"];
let D_M_Y_Text = ["01-01-49", "31-12-49", "01-01-50"];
for date_str in Y_M_D_Text {
println!("{:?}", NaiveDate::parse_from_str(date_str, Y_M_D));
}
for date_str in D_M_Y_Text {
println!("{:?}", NaiveDate::parse_from_str(date_str, D_M_Y));
}
}
// Ok(2049-01-01)
// Ok(2049-12-31)
// Ok(2050-01-01)
// Ok(2049-01-01)
// Ok(2049-12-31)
// Ok(2050-01-01) Must be some polars optimized performance implementation that is not using chrono?! 😆 Anyway, as a side note, would strongly advise you to use a clear and unambiguous format whenever possible! 😉 |
there's a fast-path for some fixed-length-formats, it might be that |
python's docs for
I suggest that even if we don't agree on implementing a way to control this in
Unfornately, I encountered this with data received from a third party - certainly not a fan of YY myself if I can avoid it. |
One possible solution, given that this is already being handled by polars, rather than delegated to chrono, is to add a new format specifier, perhaps This would be in line with the convention in chrono for allowing a number between the |
Description
Currently when parsing dates with 2-digit years, any number upto 49 is assumed to be the 21st century and 50 or more is assumed to be the 20th century so that:
There are obviously ways around this, for example
But it would be good to have direct control over the assumed century cutoff being 2050. Potentially something set via
pl.Config
, or as an extra argument toExpr.str.to_date
?The text was updated successfully, but these errors were encountered: