From fbb4ce254c8a9135cb534ae314cbb600db4212c1 Mon Sep 17 00:00:00 2001 From: raisadz <34237447+raisadz@users.noreply.github.com> Date: Sun, 29 Dec 2024 10:20:38 +0000 Subject: [PATCH] feat: add `to_lowercase` and `to_uppercase` to duckdb --- narwhals/_duckdb/expr.py | 20 ++++++++++++++++++- .../str/to_uppercase_to_lowercase_test.py | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/narwhals/_duckdb/expr.py b/narwhals/_duckdb/expr.py index fa4323171..902da2c9b 100644 --- a/narwhals/_duckdb/expr.py +++ b/narwhals/_duckdb/expr.py @@ -370,7 +370,7 @@ def is_between( closed: Literal["left", "right", "none", "both"], ) -> Self: def func( - _input: duckdb.Expression, lower_bound, upper_bound + _input: duckdb.Expression, lower_bound: Any, upper_bound: Any ) -> duckdb.Expression: if closed == "left": return (_input >= lower_bound) & (_input < upper_bound) @@ -573,6 +573,24 @@ def func(_input: duckdb.Expression) -> duckdb.Expression: returns_scalar=False, ) + def to_lowercase(self) -> DuckDBExpr: + from duckdb import FunctionExpression + + return self._compliant_expr._from_call( + lambda _input: FunctionExpression("lower", _input), + "to_lowercase", + returns_scalar=False, + ) + + def to_uppercase(self) -> DuckDBExpr: + from duckdb import FunctionExpression + + return self._compliant_expr._from_call( + lambda _input: FunctionExpression("upper", _input), + "to_uppercase", + returns_scalar=False, + ) + class DuckDBExprDateTimeNamespace: def __init__(self, expr: DuckDBExpr) -> None: diff --git a/tests/expr_and_series/str/to_uppercase_to_lowercase_test.py b/tests/expr_and_series/str/to_uppercase_to_lowercase_test.py index 6ab26ac41..a067f7e49 100644 --- a/tests/expr_and_series/str/to_uppercase_to_lowercase_test.py +++ b/tests/expr_and_series/str/to_uppercase_to_lowercase_test.py @@ -39,6 +39,7 @@ def test_str_to_uppercase( "pandas_pyarrow_constructor", "pyarrow_table_constructor", "modin_constructor", + "duckdb_lazy_constructor", ) or ("dask" in str(constructor) and PYARROW_VERSION >= (12,)) ): @@ -80,6 +81,7 @@ def test_str_to_uppercase_series( "pandas_nullable_constructor", "polars_eager_constructor", "cudf_constructor", + "duckdb_lazy_constructor", ) ): # We are marking it xfail for these conditions above