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

feat(python,rust): add date pattern dd.mm.YYYY #16045

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/polars-time/src/chunkedarray/string/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand Down
20 changes: 20 additions & 0 deletions py-polars/tests/unit/namespaces/test_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
[
Expand Down
Loading