From e5dc47431be30f49d7e1c0771193a2fdc714ed31 Mon Sep 17 00:00:00 2001 From: Bruno Conde Kind Date: Thu, 11 Jul 2024 05:40:18 -0300 Subject: [PATCH] Moved/renamed test_expr_unary to expr/unary_test::test_unary (#486) * Moved/renamed test_expr_unary to expr/unary_test::test_unary * Update tests/expr/unary_test.py Co-authored-by: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com> --------- Co-authored-by: Marco Edward Gorelli Co-authored-by: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com> --- tests/expr/unary_test.py | 22 ++++++++++++++++++++++ tests/frame/test_common.py | 18 ------------------ 2 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 tests/expr/unary_test.py diff --git a/tests/expr/unary_test.py b/tests/expr/unary_test.py new file mode 100644 index 000000000..c13084436 --- /dev/null +++ b/tests/expr/unary_test.py @@ -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) diff --git a/tests/frame/test_common.py b/tests/frame/test_common.py index 69be5e6d1..99a16de60 100644 --- a/tests/frame/test_common.py +++ b/tests/frame/test_common.py @@ -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(