forked from narwhals-dev/narwhals
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b454de5
commit f4acbbf
Showing
2 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
from narwhals.dependencies import is_dask_dataframe | ||
from tests.utils import Constructor | ||
from tests.utils import assert_equal_data | ||
|
||
data = {"a": [1, 2, 3], "b": [4, 5, 6], "z": [7.0, 8.0, 9.0]} | ||
|
||
input_list = {"a": [2, 4, 6, 8]} | ||
expected = [2, 3, 4] | ||
|
||
|
||
def test_map_batches_expr(constructor: Constructor) -> None: | ||
if is_dask_dataframe(constructor(data)): # Remove | ||
pytest.skip() | ||
df = nw.from_native(constructor(data)) | ||
e = df.select(nw.col("a").map_batches(lambda s: s + 1)) | ||
assert_equal_data(e, {"a": expected}) | ||
|
||
|
||
def test_map_batches_expr_numpy(constructor: Constructor) -> None: | ||
if is_dask_dataframe(constructor(data)): # Remove | ||
pytest.skip() | ||
df = nw.from_native(constructor(data)) | ||
e = df.select( | ||
nw.col("a").map_batches(lambda s: s.to_numpy() + 1, return_dtype=nw.Float64).sum() | ||
) | ||
assert_equal_data(e, {"a": [9.0]}) |