Skip to content

Commit

Permalink
feat: DuckDB dt.to_string (#1794)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Marco Edward Gorelli <[email protected]>
  • Loading branch information
raisadz and MarcoGorelli authored Jan 11, 2025
1 parent a729b3e commit 346724e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions narwhals/_duckdb/expr_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ def nanosecond(self) -> DuckDBExpr:
returns_scalar=self._compliant_expr._returns_scalar,
)

def to_string(self, format: str) -> DuckDBExpr: # noqa: A002
from duckdb import ConstantExpression
from duckdb import FunctionExpression

return self._compliant_expr._from_call(
lambda _input: FunctionExpression(
"strftime", _input, ConstantExpression(format)
),
"to_string",
returns_scalar=self._compliant_expr._returns_scalar,
)

def weekday(self) -> DuckDBExpr:
from duckdb import FunctionExpression

Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/dt/to_string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_dt_to_string_series(constructor_eager: ConstructorEager, fmt: str) -> N
def test_dt_to_string_expr(
constructor: Constructor, fmt: str, request: pytest.FixtureRequest
) -> None:
if ("pyspark" in str(constructor)) or "duckdb" in str(constructor):
if "pyspark" in str(constructor):
request.applymarker(pytest.mark.xfail)
input_frame = nw.from_native(constructor(data))

Expand Down Expand Up @@ -180,7 +180,7 @@ def test_dt_to_string_iso_local_date_expr(
expected: str,
request: pytest.FixtureRequest,
) -> None:
if ("pyspark" in str(constructor)) or "duckdb" in str(constructor):
if "pyspark" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = constructor({"a": [data]})
result = nw.from_native(df).with_columns(
Expand Down

0 comments on commit 346724e

Please sign in to comment.