Skip to content

Commit

Permalink
feat: add to_lowercase and to_uppercase to duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
raisadz committed Dec 29, 2024
1 parent 6b6c3ef commit fbb4ce2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion narwhals/_duckdb/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/str/to_uppercase_to_lowercase_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,))
):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fbb4ce2

Please sign in to comment.