From 8d2cbb0f13c01895a24d19189e7b0e6144d4360f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Sun, 28 Jul 2024 20:24:49 +0200 Subject: [PATCH] Added arrow sum method (#662) --- narwhals/_dask/expr.py | 6 ++++++ tests/dask_test.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/narwhals/_dask/expr.py b/narwhals/_dask/expr.py index 07102fc36..82216d9bf 100644 --- a/narwhals/_dask/expr.py +++ b/narwhals/_dask/expr.py @@ -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) diff --git a/tests/dask_test.py b/tests/dask_test.py index 376ae56d9..65d6bd2cf 100644 --- a/tests/dask_test.py +++ b/tests/dask_test.py @@ -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"), [