Skip to content

Commit

Permalink
feat: dask namespace lit (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi authored Aug 10, 2024
1 parent 2e9b3ef commit ce2c022
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions narwhals/_dask/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ def col(self, *column_names: str) -> DaskExpr:
backend_version=self._backend_version,
)

def lit(self, value: Any, dtype: dtypes.DType | None) -> DaskExpr:
# TODO @FBruzzesi: cast to dtype once `reverse_translate_dtype` is implemented.
# It should be enough to add `.astype(reverse_translate_dtype(dtype))`
return DaskExpr(
lambda df: [df._native_dataframe.assign(lit=value).loc[:, "lit"]],
depth=0,
function_name="lit",
root_names=None,
output_names=["lit"],
returns_scalar=False,
backend_version=self._backend_version,
)

def min(self, *column_names: str) -> DaskExpr:
return DaskExpr.from_column_names(
*column_names,
Expand Down
2 changes: 1 addition & 1 deletion tests/frame/lit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def test_lit(
constructor: Any, dtype: DType | None, expected_lit: list[Any], request: Any
) -> None:
if "dask" in str(constructor):
if "dask" in str(constructor) and dtype == nw.String:
request.applymarker(pytest.mark.xfail)
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df_raw = constructor(data)
Expand Down

0 comments on commit ce2c022

Please sign in to comment.