Skip to content

Commit 9987986

Browse files
authored
Merge pull request #88 from ym-pett/create_expr_list
feature: created expr_list and implemented simple functions for it
2 parents 7f6a8f4 + b46210d commit 9987986

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

narwhals_daft/expr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from narwhals.compliant import CompliantExpr
1414

1515
from narwhals_daft.expr_dt import ExprDateTimeNamesSpace
16+
from narwhals_daft.expr_list import ExprListNamespace
1617
from narwhals_daft.expr_name import ExprNameNamespace
1718
from narwhals_daft.expr_str import ExprStringNamespace
1819
from narwhals_daft.utils import evaluate_literal, extend_bool, narwhals_to_native_dtype
@@ -855,6 +856,10 @@ def str(self) -> ExprStringNamespace:
855856
def dt(self) -> ExprDateTimeNamesSpace:
856857
return ExprDateTimeNamesSpace(self)
857858

859+
@property
860+
def list(self) -> ExprListNamespace:
861+
return ExprListNamespace(self)
862+
858863
drop_nulls = not_implemented()
859864
fill_nan = not_implemented()
860865
filter = not_implemented()
@@ -871,6 +876,5 @@ def dt(self) -> ExprDateTimeNamesSpace:
871876

872877
# namespaces
873878
cat = not_implemented() # pyright: ignore[reportAssignmentType]
874-
list = not_implemented() # pyright: ignore[reportAssignmentType]
875879
struct = not_implemented() # pyright: ignore[reportAssignmentType]
876880
any_value = not_implemented()

narwhals_daft/expr_list.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
import daft.functions as F
6+
from narwhals._compliant.any_namespace import ListNamespace
7+
from narwhals._utils import not_implemented
8+
9+
if TYPE_CHECKING:
10+
from narwhals_daft.expr import DaftExpr
11+
12+
13+
class ExprListNamespace(ListNamespace["DaftExpr"]):
14+
def __init__(self, expr: DaftExpr, /) -> None:
15+
self._compliant = expr
16+
17+
@property
18+
def compliant(self) -> DaftExpr:
19+
return self._compliant
20+
21+
def len(self) -> DaftExpr:
22+
return self.compliant._with_elementwise(lambda expr: F.list_count(expr, "all"))
23+
24+
def min(self) -> DaftExpr:
25+
return self.compliant._with_elementwise(lambda expr: F.list_min(expr))
26+
27+
def max(self) -> DaftExpr:
28+
return self.compliant._with_elementwise(lambda expr: F.list_max(expr))
29+
30+
def mean(self) -> DaftExpr:
31+
return self.compliant._with_elementwise(lambda expr: F.list_mean(expr))
32+
33+
unique = not_implemented()
34+
contains = not_implemented()
35+
get = not_implemented()
36+
median = not_implemented()
37+
sum = not_implemented()

run_tests.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@
5555
"test_joinasof_time",
5656
"test_kurtosis_expr",
5757
"test_left_to_right_broadcasting",
58-
"test_len_expr",
5958
"test_mapping_key_not_in_expr",
60-
"test_max_expr",
61-
"test_mean_expr",
6259
"test_median_expr",
6360
"test_median_expr_raises_on_str",
64-
"test_min_expr",
6561
"test_missing_columns",
6662
"test_mode_expr_keep_all_lazy",
6763
"test_mode_expr_keep_any",

0 commit comments

Comments
 (0)