diff --git a/crates/polars-time/src/chunkedarray/string/patterns.rs b/crates/polars-time/src/chunkedarray/string/patterns.rs index e42828b3bee2..16c5689a95d5 100644 --- a/crates/polars-time/src/chunkedarray/string/patterns.rs +++ b/crates/polars-time/src/chunkedarray/string/patterns.rs @@ -2,6 +2,7 @@ //! parsing different orders of dates in a single column. pub(super) static DATE_D_M_Y: &[&str] = &[ + "%d.%m.%Y", // 31.12.2021 "%d-%m-%Y", // 31-12-2021 "%d/%m/%Y", // 31/12/2021 ]; diff --git a/py-polars/tests/unit/namespaces/test_strptime.py b/py-polars/tests/unit/namespaces/test_strptime.py index b8aed6d6121d..3988ebffbdf4 100644 --- a/py-polars/tests/unit/namespaces/test_strptime.py +++ b/py-polars/tests/unit/namespaces/test_strptime.py @@ -132,6 +132,26 @@ def test_to_date_non_exact_strptime() -> None: s.str.to_date(format, strict=True, exact=True) +@pytest.mark.parametrize( + ("time_string", "expected"), + [ + ("01-02-2024", date(2024, 2, 1)), + ("01.02.2024", date(2024, 2, 1)), + ("01/02/2024", date(2024, 2, 1)), + ("2024-02-01", date(2024, 2, 1)), + ("2024/02/01", date(2024, 2, 1)), + ("31-12-2024", date(2024, 12, 31)), + ("31.12.2024", date(2024, 12, 31)), + ("31/12/2024", date(2024, 12, 31)), + ("2024-12-31", date(2024, 12, 31)), + ("2024/12/31", date(2024, 12, 31)), + ], +) +def test_to_date_all_inferred_date_patterns(time_string: str, expected: date) -> None: + result = pl.Series([time_string]).str.to_date() + assert result[0] == expected + + @pytest.mark.parametrize( ("value", "attr"), [