Skip to content

Commit 9a4c7e9

Browse files
authored
Merge pull request #92 from raisadz/feat/fill_nan_pow
feat: add `fill_nan` and fix `pow`
2 parents 6538419 + 94ef5f9 commit 9a4c7e9

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

narwhals_daft/expr.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,9 @@ def __rmod__(self, other: DaftExpr) -> DaftExpr:
420420
)
421421

422422
def __pow__(self, other: DaftExpr) -> DaftExpr:
423-
if other._metadata.is_literal:
424-
other_lit = evaluate_literal(other)
425-
return self._with_callable(lambda expr: (expr**other_lit))
426-
msg = "`pow` with non-literal input is not yet supported"
427-
raise NotImplementedError(msg)
423+
return self._with_elementwise(
424+
lambda _input, expr: F.pow(_input, expr), expr=other
425+
)
428426

429427
def __rpow__(self, other: DaftExpr) -> DaftExpr:
430428
if other._metadata.is_literal:
@@ -844,6 +842,14 @@ def _partitioned_rank(
844842

845843
return self._with_callable(_unpartitioned_rank, _partitioned_rank)
846844

845+
def fill_nan(self, value: float | None) -> DaftExpr:
846+
def func(expr: Expression) -> Expression:
847+
if value is None:
848+
return F.when(expr.is_nan(), lit(None)).otherwise(expr)
849+
return expr.fill_nan(lit(value))
850+
851+
return self._with_callable(func)
852+
847853
@property
848854
def name(self) -> ExprNameNamespace:
849855
return ExprNameNamespace(self)
@@ -861,7 +867,6 @@ def list(self) -> ExprListNamespace:
861867
return ExprListNamespace(self)
862868

863869
drop_nulls = not_implemented()
864-
fill_nan = not_implemented()
865870
filter = not_implemented()
866871
ewm_mean = not_implemented()
867872
kurtosis = not_implemented()

run_tests.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"test_any_value_expr",
88
"test_any_value_group_by",
99
"test_any_value_over",
10-
"test_arithmetic_expr",
1110
"test_arithmetic_expr_left_literal",
1211
"test_cast",
1312
"test_cast_binary",
@@ -33,7 +32,6 @@
3332
"test_expr_binary",
3433
"test_expr_floordiv_by_zero",
3534
"test_expr_rfloordiv_by_zero",
36-
"test_fill_nan",
3735
"test_fill_null_limits",
3836
"test_fill_null_strategies_with_limit_as_none",
3937
"test_fill_null_strategies_with_partition_by",
@@ -81,7 +79,6 @@
8179
"test_over_when_then_aggregation_partition_by",
8280
"test_package_version",
8381
"test_parse_weight",
84-
"test_pipe_expr",
8582
"test_quantile_expr",
8683
"test_rank_with_order_by",
8784
"test_rank_with_order_by_and_partition_by",

0 commit comments

Comments
 (0)