-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
Series|Expr.is_finite
method (#1341)
- Loading branch information
Showing
10 changed files
with
178 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
- clip | ||
- is_between | ||
- is_duplicated | ||
- is_finite | ||
- is_first_distinct | ||
- is_in | ||
- is_last_distinct | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
- is_between | ||
- is_duplicated | ||
- is_empty | ||
- is_finite | ||
- is_first_distinct | ||
- is_in | ||
- is_last_distinct | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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, None]} | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast") | ||
def test_is_finite_expr(constructor: Constructor) -> None: | ||
if "polars" in str(constructor) or "pyarrow_table" in str(constructor): | ||
expected = {"a": [False, False, True, None]} | ||
elif "pandas_constructor" in str(constructor) or "dask" in str(constructor): | ||
expected = {"a": [False, False, True, False]} | ||
else: # pandas_nullable_constructor, pandas_pyarrow_constructor, modin | ||
expected = {"a": [None, False, True, 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: | ||
if "polars" in str(constructor_eager) or "pyarrow_table" in str(constructor_eager): | ||
expected = {"a": [False, False, True, None]} | ||
elif "pandas_constructor" in str(constructor_eager) or "dask" in str( | ||
constructor_eager | ||
): | ||
expected = {"a": [False, False, True, False]} | ||
else: # pandas_nullable_constructor, pandas_pyarrow_constructor, modin | ||
expected = {"a": [None, False, True, None]} | ||
|
||
df = nw.from_native(constructor_eager(data), eager_only=True) | ||
result = {"a": df["a"].is_finite()} | ||
|
||
assert_equal_data(result, expected) |