From d7323f853762e239b9f1e2460dd4aabd5f142a2d Mon Sep 17 00:00:00 2001 From: Magdalena Kowalczuk <74981211+anopsy@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:49:36 +0000 Subject: [PATCH] add dask null-count --- narwhals/_dask/expr.py | 7 +++++++ tests/expr_and_series/null_count_test.py | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/narwhals/_dask/expr.py b/narwhals/_dask/expr.py index 62dc16460..c111b5153 100644 --- a/narwhals/_dask/expr.py +++ b/narwhals/_dask/expr.py @@ -538,6 +538,13 @@ def func(_input: Any) -> Any: returns_scalar=False, ) + def null_count(self: Self) -> Self: + return self._from_call( + lambda _input: _input.isna().sum(), + "null_count", + returns_scalar=True, + ) + def tail(self: Self) -> NoReturn: # We can't (yet?) allow methods which modify the index msg = "`Expr.tail` is not supported for the Dask backend. Please use `LazyFrame.tail` instead." diff --git a/tests/expr_and_series/null_count_test.py b/tests/expr_and_series/null_count_test.py index 768264692..a6cb58f71 100644 --- a/tests/expr_and_series/null_count_test.py +++ b/tests/expr_and_series/null_count_test.py @@ -1,7 +1,5 @@ from typing import Any -import pytest - import narwhals.stable.v1 as nw from tests.utils import compare_dicts @@ -11,9 +9,7 @@ } -def test_null_count_expr(constructor: Any, request: Any) -> None: - if "dask" in str(constructor): - request.applymarker(pytest.mark.xfail) +def test_null_count_expr(constructor: Any) -> None: df = nw.from_native(constructor(data)) result = df.select(nw.all().null_count()) expected = {