Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion narwhals_daft/expr_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
from typing import TYPE_CHECKING

import daft.functions as F
from daft import lit
from narwhals._compliant.any_namespace import ListNamespace
from narwhals._utils import not_implemented

if TYPE_CHECKING:
from daft import Expression

from narwhals_daft.expr import DaftExpr


Expand All @@ -30,8 +33,15 @@ def max(self) -> DaftExpr:
def mean(self) -> DaftExpr:
return self.compliant._with_elementwise(lambda expr: F.list_mean(expr))

def sum(self) -> DaftExpr:
def func(expr: Expression) -> Expression:
return F.when(F.list_count(expr, "valid") == lit(0), lit(0)).otherwise(
F.list_sum(expr)
)

return self.compliant._with_elementwise(func)

unique = not_implemented()
contains = not_implemented()
get = not_implemented()
median = not_implemented()
sum = not_implemented()
1 change: 0 additions & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"test_str_replace_expr_scalar",
"test_str_strip_chars",
"test_str_zfill",
"test_sum_expr",
"test_sumh_broadcasting",
"test_sumh_transformations",
"test_timestamp_dates",
Expand Down