-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Series|Expr.is_finite
method
#1341
Open
FBruzzesi
wants to merge
8
commits into
main
Choose a base branch
from
feat/is-finite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
β2
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
89fe3f4
is-finite for eager
FBruzzesi cc3e722
add dask and test
FBruzzesi 7aff971
Merge branch 'main' into feat/is-finite
FBruzzesi f603f6b
pandas treat nulls as nan
FBruzzesi 28d329a
rm dask from series warning
FBruzzesi 46f7baa
xfail py38 pandas_pyarrow
FBruzzesi d6afe01
pin numpy instead
FBruzzesi 40a894d
nevermind its pandas version to pin
FBruzzesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -21,6 +21,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 |
---|---|---|
|
@@ -26,6 +26,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,44 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
from tests.utils import PANDAS_VERSION | ||
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(request: pytest.FixtureRequest, constructor: Constructor) -> None: | ||
if PANDAS_VERSION < (2, 2) and "pandas_pyarrow" in str(constructor): | ||
request.applymarker(pytest.mark.xfail) | ||
|
||
if "polars" in str(constructor) or "pyarrow_table" in str(constructor): | ||
expected = {"a": [False, False, True, None]} | ||
else: | ||
expected = {"a": [False, False, True, False]} | ||
|
||
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( | ||
request: pytest.FixtureRequest, constructor_eager: ConstructorEager | ||
) -> None: | ||
if PANDAS_VERSION < (2, 2) and "pandas_pyarrow" in str(constructor_eager): | ||
request.applymarker(pytest.mark.xfail) | ||
|
||
if "polars" in str(constructor_eager) or "pyarrow_table" in str(constructor_eager): | ||
expected = {"a": [False, False, True, None]} | ||
else: | ||
expected = {"a": [False, False, True, False]} | ||
|
||
df = nw.from_native(constructor_eager(data), eager_only=True) | ||
result = {"a": df["a"].is_finite()} | ||
|
||
assert_equal_data(result, expected) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a opinionated choice that na is not finite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€ no sure, wouldn't we want to preserve null values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior is different for different pandas backend dtype. Let me come back with an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm actually, for classical pandas types, we wouldn't have the option of returning a nullable boolean (if we want to preserve the dtype backend)
π€ gonna think about this a little longer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These would be the output:
While for polars: