From 0af14cd55996e26234a46503fd5d671f2b740d02 Mon Sep 17 00:00:00 2001 From: raisadz <34237447+raisadz@users.noreply.github.com> Date: Sat, 11 Jan 2025 15:55:44 +0000 Subject: [PATCH] feat: DuckDB `dt.weekday` (#1795) --- narwhals/_duckdb/expr_dt.py | 9 +++++++++ tests/expr_and_series/dt/datetime_attributes_test.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/narwhals/_duckdb/expr_dt.py b/narwhals/_duckdb/expr_dt.py index dc05ebd2d..eb80d5b07 100644 --- a/narwhals/_duckdb/expr_dt.py +++ b/narwhals/_duckdb/expr_dt.py @@ -93,3 +93,12 @@ def nanosecond(self) -> DuckDBExpr: "nanosecond", returns_scalar=self._compliant_expr._returns_scalar, ) + + def weekday(self) -> DuckDBExpr: + from duckdb import FunctionExpression + + return self._compliant_expr._from_call( + lambda _input: FunctionExpression("isodow", _input), + "weekday", + returns_scalar=self._compliant_expr._returns_scalar, + ) diff --git a/tests/expr_and_series/dt/datetime_attributes_test.py b/tests/expr_and_series/dt/datetime_attributes_test.py index 9f578d3c1..a2a379898 100644 --- a/tests/expr_and_series/dt/datetime_attributes_test.py +++ b/tests/expr_and_series/dt/datetime_attributes_test.py @@ -49,7 +49,7 @@ def test_datetime_attributes( request.applymarker(pytest.mark.xfail) if attribute == "date" and "cudf" in str(constructor): request.applymarker(pytest.mark.xfail) - if "duckdb" in str(constructor) and attribute in ("date", "weekday", "ordinal_day"): + if "duckdb" in str(constructor) and attribute in ("date", "ordinal_day"): request.applymarker(pytest.mark.xfail) if "pyspark" in str(constructor): request.applymarker(pytest.mark.xfail)