-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: arrow and dask expr
clip
method (#729)
* feat: arrow and dask clip * merge main, add returns_scalar
- Loading branch information
Showing
6 changed files
with
59 additions
and
18 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
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 |
---|---|---|
|
@@ -634,11 +634,11 @@ def clip( | |
Series: '' [i64] | ||
[ | ||
-1 | ||
1 | ||
1 | ||
-1 | ||
3 | ||
3 | ||
-1 | ||
3 | ||
3 | ||
] | ||
""" | ||
return self._from_compliant_series( | ||
|
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 |
---|---|---|
@@ -1,24 +1,35 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
from tests.utils import compare_dicts | ||
|
||
|
||
def test_clip(request: Any, constructor: Any) -> None: | ||
if "pyarrow_table" in str(constructor) or "dask" in str(constructor): | ||
request.applymarker(pytest.mark.xfail) | ||
def test_clip(constructor: Any) -> None: | ||
df = nw.from_native(constructor({"a": [1, 2, 3, -4, 5]})) | ||
result = df.select(b=nw.col("a").clip(3, 5)) | ||
expected = {"b": [3, 3, 3, 3, 5]} | ||
result = df.select( | ||
lower_only=nw.col("a").clip(lower_bound=3), | ||
upper_only=nw.col("a").clip(upper_bound=4), | ||
both=nw.col("a").clip(3, 4), | ||
) | ||
expected = { | ||
"lower_only": [3, 3, 3, 3, 5], | ||
"upper_only": [1, 2, 3, -4, 4], | ||
"both": [3, 3, 3, 3, 4], | ||
} | ||
compare_dicts(result, expected) | ||
|
||
|
||
def test_clip_series(request: Any, constructor_eager: Any) -> None: | ||
if "pyarrow_table" in str(constructor_eager): | ||
request.applymarker(pytest.mark.xfail) | ||
def test_clip_series(constructor_eager: Any) -> None: | ||
df = nw.from_native(constructor_eager({"a": [1, 2, 3, -4, 5]}), eager_only=True) | ||
result = {"b": df["a"].clip(3, 5)} | ||
expected = {"b": [3, 3, 3, 3, 5]} | ||
result = { | ||
"lower_only": df["a"].clip(lower_bound=3), | ||
"upper_only": df["a"].clip(upper_bound=4), | ||
"both": df["a"].clip(3, 4), | ||
} | ||
|
||
expected = { | ||
"lower_only": [3, 3, 3, 3, 5], | ||
"upper_only": [1, 2, 3, -4, 4], | ||
"both": [3, 3, 3, 3, 4], | ||
} | ||
compare_dicts(result, expected) |