From 6a4eb50722a9f1d4fe4ce07a332df39a680a6cfc Mon Sep 17 00:00:00 2001 From: Magdalena Kowalczuk <74981211+anopsy@users.noreply.github.com> Date: Wed, 7 Aug 2024 07:34:21 +0000 Subject: [PATCH 1/2] add DaskExpr-count and DaskExpr-drop-nulls formatted --- narwhals/_dask/expr.py | 12 ++++++++++++ tests/expr_and_series/drop_nulls_test.py | 6 +----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/narwhals/_dask/expr.py b/narwhals/_dask/expr.py index 1ad1e0778..180f4d1ce 100644 --- a/narwhals/_dask/expr.py +++ b/narwhals/_dask/expr.py @@ -267,11 +267,23 @@ def sum(self) -> Self: "sum", ) + def count(self) -> Self: + return self._from_call( + lambda _input: _input.count(), + "count", + ) + def round(self, decimals: int) -> Self: return self._from_call( lambda _input, decimals: _input.round(decimals), "round", decimals ) + def drop_nulls(self) -> Self: + return self._from_call( + lambda _input: _input.dropna(), + "drop_nulls", + ) + def fill_null(self, value: Any) -> DaskExpr: return self._from_call(lambda _input, _val: _input.fillna(_val), "fillna", value) diff --git a/tests/expr_and_series/drop_nulls_test.py b/tests/expr_and_series/drop_nulls_test.py index 26455615d..5e54e8175 100644 --- a/tests/expr_and_series/drop_nulls_test.py +++ b/tests/expr_and_series/drop_nulls_test.py @@ -2,15 +2,11 @@ from typing import Any -import pytest - import narwhals as nw from tests.utils import compare_dicts -def test_drop_nulls(constructor: Any, request: Any) -> None: - if "dask" in str(constructor): - request.applymarker(pytest.mark.xfail) +def test_drop_nulls(constructor: Any) -> None: data = { "A": [1, 2, None, 4], "B": [5, 6, 7, 8], From 59f174c90bb09c4e2f88a7a01a99aa5b00139b90 Mon Sep 17 00:00:00 2001 From: Magdalena Kowalczuk <74981211+anopsy@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:15:23 +0000 Subject: [PATCH 2/2] add dask Expr.count --- narwhals/_dask/expr.py | 7 +------ tests/expr_and_series/count_test.py | 6 +----- tests/expr_and_series/drop_nulls_test.py | 6 +++++- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/narwhals/_dask/expr.py b/narwhals/_dask/expr.py index 421eb9c31..e2a7438e4 100644 --- a/narwhals/_dask/expr.py +++ b/narwhals/_dask/expr.py @@ -297,6 +297,7 @@ def count(self) -> Self: return self._from_call( lambda _input: _input.count(), "count", + returns_scalar=True, ) def round(self, decimals: int) -> Self: @@ -307,12 +308,6 @@ def round(self, decimals: int) -> Self: returns_scalar=False, ) - def drop_nulls(self) -> Self: - return self._from_call( - lambda _input: _input.dropna(), - "drop_nulls", - ) - def fill_null(self, value: Any) -> DaskExpr: return self._from_call( lambda _input, _val: _input.fillna(_val), diff --git a/tests/expr_and_series/count_test.py b/tests/expr_and_series/count_test.py index 10feff5d9..208df3bc1 100644 --- a/tests/expr_and_series/count_test.py +++ b/tests/expr_and_series/count_test.py @@ -1,14 +1,10 @@ from typing import Any -import pytest - import narwhals.stable.v1 as nw from tests.utils import compare_dicts -def test_count(constructor: Any, request: Any) -> None: - if "dask" in str(constructor): - request.applymarker(pytest.mark.xfail) +def test_count(constructor: Any) -> None: data = {"a": [1, 3, 2], "b": [4, None, 6], "z": [7.0, None, None]} df = nw.from_native(constructor(data)) result = df.select(nw.col("a", "b", "z").count()) diff --git a/tests/expr_and_series/drop_nulls_test.py b/tests/expr_and_series/drop_nulls_test.py index 5e54e8175..26455615d 100644 --- a/tests/expr_and_series/drop_nulls_test.py +++ b/tests/expr_and_series/drop_nulls_test.py @@ -2,11 +2,15 @@ from typing import Any +import pytest + import narwhals as nw from tests.utils import compare_dicts -def test_drop_nulls(constructor: Any) -> None: +def test_drop_nulls(constructor: Any, request: Any) -> None: + if "dask" in str(constructor): + request.applymarker(pytest.mark.xfail) data = { "A": [1, 2, None, 4], "B": [5, 6, 7, 8],