Skip to content

Commit

Permalink
Added arrow sum method (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaMariaLeon authored Jul 28, 2024
1 parent 435dbea commit 8d2cbb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions narwhals/_dask/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ def is_between(
closed,
)

def sum(self) -> Self:
return self._from_call(
lambda _input: _input.sum(),
"sum",
)

@property
def str(self: Self) -> DaskExprStringNamespace:
return DaskExprStringNamespace(self)
Expand Down
10 changes: 10 additions & 0 deletions tests/dask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def test_cum_sum() -> None:
compare_dicts(result, expected)


def test_sum() -> None:
import dask.dataframe as dd

dfdd = dd.from_pandas(pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}))
df = nw.from_native(dfdd)
result = df.with_columns((nw.col("a") + nw.col("b").sum()).alias("c"))
expected = {"a": [1, 2, 3], "b": [4, 5, 6], "c": [16, 17, 18]}
compare_dicts(result, expected)


@pytest.mark.parametrize(
("closed", "expected"),
[
Expand Down

0 comments on commit 8d2cbb0

Please sign in to comment.