-
Notifications
You must be signed in to change notification settings - Fork 89
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
Showing
4 changed files
with
52 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
|
||
|
||
def test_expr_sample(request: Any, constructor: Any) -> None: | ||
if "pyarrow_table" in str(constructor): | ||
request.applymarker(pytest.mark.xfail) | ||
def test_expr_sample(constructor: Any) -> None: | ||
df = nw.from_native(constructor({"a": [1, 2, 3], "b": [4, 5, 6]})).lazy() | ||
result_shape = nw.to_native(df.select(nw.col("a").sample(n=2)).collect()).shape | ||
expected = (2, 1) | ||
assert result_shape == expected | ||
result_shape = nw.to_native(df.collect()["a"].sample(n=2)).shape | ||
expected = (2,) # type: ignore[assignment] | ||
assert result_shape == expected | ||
|
||
result_expr = df.select(nw.col("a").sample(n=2)).collect().shape | ||
expected_expr = (2, 1) | ||
assert result_expr == expected_expr | ||
|
||
result_series = df.collect()["a"].sample(n=2).shape | ||
expected_series = (2,) | ||
assert result_series == expected_series | ||
|
||
|
||
def test_expr_sample_fraction(constructor: Any) -> None: | ||
df = nw.from_native(constructor({"a": [1, 2, 3] * 10, "b": [4, 5, 6] * 10})).lazy() | ||
|
||
result_expr = df.select(nw.col("a").sample(fraction=0.1)).collect().shape | ||
expected_expr = (3, 1) | ||
assert result_expr == expected_expr | ||
|
||
result_series = df.collect()["a"].sample(fraction=0.1).shape | ||
expected_series = (3,) | ||
assert result_series == expected_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