-
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.
test: test median ignores null values
- Loading branch information
1 parent
3a48155
commit 4b8da4c
Showing
2 changed files
with
14 additions
and
17 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 |
---|---|---|
@@ -1,32 +1,38 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
from tests.utils import Constructor | ||
from tests.utils import compare_dicts | ||
from tests.utils import ConstructorEager | ||
from tests.utils import assert_equal_data | ||
|
||
data = {"a": [3, 8, 2], "b": [5, 5, 7], "z": [7.0, 8, 9]} | ||
data = { | ||
"a": [3, 8, 2, None], | ||
"b": [5, 5, None, 7], | ||
"z": [7.0, 8, 9, None], | ||
"s": ["f", "a", "x", "x"], | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"expr", [nw.col("a", "b", "z").median(), nw.median("a", "b", "z")] | ||
) | ||
def test_expr_median_expr( | ||
def test_median_expr( | ||
constructor: Constructor, expr: nw.Expr, request: pytest.FixtureRequest | ||
) -> None: | ||
if "dask_lazy_p2" in str(constructor): | ||
request.applymarker(pytest.mark.xfail) | ||
df = nw.from_native(constructor(data)) | ||
result = df.select(expr) | ||
expected = {"a": [3.0], "b": [5.0], "z": [8.0]} | ||
compare_dicts(result, expected) | ||
assert_equal_data(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize(("col", "expected"), [("a", 3.0), ("b", 5.0), ("z", 8.0)]) | ||
def test_expr_median_series(constructor_eager: Any, col: str, expected: float) -> None: | ||
def test_median_series( | ||
constructor_eager: ConstructorEager, col: str, expected: float | ||
) -> None: | ||
series = nw.from_native(constructor_eager(data), eager_only=True)[col] | ||
result = series.median() | ||
compare_dicts({col: [result]}, {col: [expected]}) | ||
assert_equal_data({col: [result]}, {col: [expected]}) |