Skip to content

Commit 6db8b4f

Browse files
authored
feat: add duckdb .str.to_datetime (#1916)
feat: duckdb str to_datetime
1 parent adb5a4a commit 6db8b4f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

narwhals/_duckdb/expr_str.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,16 @@ def replace(
126126
) -> NoReturn:
127127
msg = "`replace` is currently not supported for DuckDB"
128128
raise NotImplementedError(msg)
129+
130+
def to_datetime(self: Self, format: str | None) -> DuckDBExpr: # noqa: A002
131+
if format is None:
132+
msg = "Cannot infer format with DuckDB backend"
133+
raise NotImplementedError(msg)
134+
135+
return self._compliant_expr._from_call(
136+
lambda _input: FunctionExpression(
137+
"strptime", _input, ConstantExpression(format)
138+
),
139+
"to_datetime",
140+
expr_kind=self._compliant_expr._expr_kind,
141+
)

tests/expr_and_series/str/to_datetime_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
data = {"a": ["2020-01-01T12:34:56"]}
1919

2020

21-
def test_to_datetime(constructor: Constructor, request: pytest.FixtureRequest) -> None:
22-
if "duckdb" in str(constructor):
23-
request.applymarker(pytest.mark.xfail)
21+
def test_to_datetime(constructor: Constructor) -> None:
2422
if "cudf" in str(constructor):
2523
expected = "2020-01-01T12:34:56.000000000"
2624
else:

0 commit comments

Comments
 (0)