Skip to content

Commit

Permalink
fix: Interpret %y consistently with Chrono in to_date/to_datetime/str…
Browse files Browse the repository at this point in the history
…ptime (#17661)
  • Loading branch information
MarcoGorelli authored Jul 16, 2024
1 parent 20babcd commit 3897a37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/polars-time/src/chunkedarray/string/strptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl StrpTimeState {
return None;
}

if decade < 50 {
if decade < 70 {
year = 2000 + decade;
} else {
year = 1900 + decade;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import sys
from datetime import datetime
from datetime import date, datetime
from typing import TYPE_CHECKING

import hypothesis.strategies as st
Expand Down Expand Up @@ -187,3 +187,19 @@ def test_to_datetime_aware_values_aware_dtype() -> None:
dtype=pl.Datetime("us", "Asia/Kathmandu"),
)
assert_series_equal(result, expected)


@pytest.mark.parametrize(
("inputs", "format", "expected"),
[
("01-01-69", "%d-%m-%y", date(2069, 1, 1)), # Polars' parser
("01-01-70", "%d-%m-%y", date(1970, 1, 1)), # Polars' parser
("01-January-69", "%d-%B-%y", date(2069, 1, 1)), # Chrono
("01-January-70", "%d-%B-%y", date(1970, 1, 1)), # Chrono
],
)
def test_to_datetime_two_digit_year_17213(
inputs: str, format: str, expected: date
) -> None:
result = pl.Series([inputs]).str.to_date(format=format).item()
assert result == expected

0 comments on commit 3897a37

Please sign in to comment.