diff --git a/narwhals/_polars/namespace.py b/narwhals/_polars/namespace.py index 21c0937a1..4eb8451b7 100644 --- a/narwhals/_polars/namespace.py +++ b/narwhals/_polars/namespace.py @@ -117,15 +117,6 @@ def mean_horizontal(self, *exprs: IntoPolarsExpr) -> PolarsExpr: dtypes=self._dtypes, ) - def median(self, *column_names: str) -> PolarsExpr: - import polars as pl # ignore-banned-import() - - from narwhals._polars.expr import PolarsExpr - - if self._backend_version < (0, 20, 4): # pragma: no cover - return PolarsExpr(pl.median([*column_names]), dtypes=self._dtypes) # type: ignore[arg-type] - return PolarsExpr(pl.median(*column_names), dtypes=self._dtypes) - def concat_str( self, exprs: Iterable[IntoPolarsExpr], diff --git a/tests/expr_and_series/median_test.py b/tests/expr_and_series/median_test.py index 33881cea1..3fb62762e 100644 --- a/tests/expr_and_series/median_test.py +++ b/tests/expr_and_series/median_test.py @@ -1,20 +1,24 @@ 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): @@ -22,11 +26,13 @@ def test_expr_median_expr( 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]})