Skip to content

Commit

Permalink
Moved/renamed test_expr_unary to expr/unary_test::test_unary (#486)
Browse files Browse the repository at this point in the history
* Moved/renamed test_expr_unary to expr/unary_test::test_unary

* Update tests/expr/unary_test.py

Co-authored-by: Francesco Bruzzesi <[email protected]>

---------

Co-authored-by: Marco Edward Gorelli <[email protected]>
Co-authored-by: Francesco Bruzzesi <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent 7e72d88 commit e5dc474
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
22 changes: 22 additions & 0 deletions tests/expr/unary_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Any

import narwhals as nw
from tests.utils import compare_dicts


def test_unary(constructor_with_lazy: Any) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
result = (
nw.from_native(constructor_with_lazy(data))
.with_columns(
a_mean=nw.col("a").mean(),
a_sum=nw.col("a").sum(),
b_nunique=nw.col("b").n_unique(),
z_min=nw.col("z").min(),
z_max=nw.col("z").max(),
)
.select(nw.col("a_mean", "a_sum", "b_nunique", "z_min", "z_max").unique())
)
result_native = nw.to_native(result)
expected = {"a_mean": [2], "a_sum": [6], "b_nunique": [2], "z_min": [7], "z_max": [9]}
compare_dicts(result_native, expected)
18 changes: 0 additions & 18 deletions tests/frame/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,6 @@ def test_expr_binary(df_raw: Any) -> None:
compare_dicts(result_native, expected)


@pytest.mark.parametrize("df_raw", [df_polars, df_pandas, df_lazy])
def test_expr_unary(df_raw: Any) -> None:
result = (
nw.from_native(df_raw)
.with_columns(
a_mean=nw.col("a").mean(),
a_sum=nw.col("a").sum(),
b_nunique=nw.col("b").n_unique(),
z_min=nw.col("z").min(),
z_max=nw.col("z").max(),
)
.select(nw.col("a_mean", "a_sum", "b_nunique", "z_min", "z_max").unique())
)
result_native = nw.to_native(result)
expected = {"a_mean": [2], "a_sum": [6], "b_nunique": [2], "z_min": [7], "z_max": [9]}
compare_dicts(result_native, expected)


@pytest.mark.parametrize("df_raw", [df_polars, df_pandas, df_mpd, df_lazy])
def test_expr_transform(df_raw: Any) -> None:
result = nw.from_native(df_raw).with_columns(
Expand Down

0 comments on commit e5dc474

Please sign in to comment.