Skip to content

Commit

Permalink
add dask and test
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Nov 1, 2024
1 parent 89fe3f4 commit cc3e722
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions narwhals/_dask/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,15 @@ def func(_input: Any, dtype: DType | type[DType]) -> Any:
returns_scalar=False,
)

def is_finite(self: Self) -> Self:
import dask.array as da # ignore-banned-import

return self._from_call(
lambda _input: da.isfinite(_input),
"is_finite",
returns_scalar=False,
)


class DaskExprStringNamespace:
def __init__(self, expr: DaskExpr) -> None:
Expand Down
27 changes: 27 additions & 0 deletions tests/expr_and_series/is_finite_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import assert_equal_data

data = {"a": [float("nan"), float("inf"), 2.0]}
expected = {"a": [False, False, True]}


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast")
def test_is_finite_expr(constructor: Constructor) -> None:
df = nw.from_native(constructor(data))
result = df.select(nw.col("a").is_finite())

assert_equal_data(result, expected)


@pytest.mark.filterwarnings("ignore:invalid value encountered in cast")
def test_is_finite_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)
result = {"a": df["a"].is_finite()}

assert_equal_data(result, expected)

0 comments on commit cc3e722

Please sign in to comment.