From ebe37d9b79374fb838a16d32b06a9a52d1340219 Mon Sep 17 00:00:00 2001 From: Graziano Montanaro <40232320+montanarograziano@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:43:48 +0200 Subject: [PATCH] chore: factor `test_std` outside `test_common` (#657) * Moved test_std outside test_common * Swapped constructor_eager fixture with constructor in test_std --- pyproject.toml | 2 +- tests/frame/std_test.py | 25 +++++++++++++++++++++++++ tests/frame/test_common.py | 19 ------------------- 3 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 tests/frame/std_test.py diff --git a/pyproject.toml b/pyproject.toml index a835c6b9d..2f6062435 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,7 @@ filterwarnings = [ 'ignore:.*defaulting to pandas implementation', 'ignore:.*implementation has mismatches with pandas', 'ignore:.*Do not use the `random` module inside strategies', - 'ignore:.*You are using pyarrow version 12', + 'ignore:.*You are using pyarrow version', ] xfail_strict = true markers = ["slow: marks tests as slow (deselect with '-m \"not slow\"')"] diff --git a/tests/frame/std_test.py b/tests/frame/std_test.py new file mode 100644 index 000000000..3133810d5 --- /dev/null +++ b/tests/frame/std_test.py @@ -0,0 +1,25 @@ +from typing import Any + +import narwhals.stable.v1 as nw +from tests.utils import compare_dicts + +data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]} + + +def test_std(constructor: Any) -> None: + df = nw.from_native(constructor(data)) + result = df.select( + nw.col("a").std().alias("a_ddof_default"), + nw.col("a").std(ddof=1).alias("a_ddof_1"), + nw.col("a").std(ddof=0).alias("a_ddof_0"), + nw.col("b").std(ddof=2).alias("b_ddof_2"), + nw.col("z").std(ddof=0).alias("z_ddof_0"), + ) + expected = { + "a_ddof_default": [1.0], + "a_ddof_1": [1.0], + "a_ddof_0": [0.816497], + "b_ddof_2": [1.632993], + "z_ddof_0": [0.816497], + } + compare_dicts(result, expected) diff --git a/tests/frame/test_common.py b/tests/frame/test_common.py index 8ae6741aa..e950d4b48 100644 --- a/tests/frame/test_common.py +++ b/tests/frame/test_common.py @@ -19,25 +19,6 @@ data_right = {"c": [6, 12, -1], "d": [0, -4, 2]} -def test_std(constructor_eager: Any) -> None: - df = nw.from_native(constructor_eager(data)) - result = df.select( - nw.col("a").std().alias("a_ddof_default"), - nw.col("a").std(ddof=1).alias("a_ddof_1"), - nw.col("a").std(ddof=0).alias("a_ddof_0"), - nw.col("b").std(ddof=2).alias("b_ddof_2"), - nw.col("z").std(ddof=0).alias("z_ddof_0"), - ) - expected = { - "a_ddof_default": [1.0], - "a_ddof_1": [1.0], - "a_ddof_0": [0.816497], - "b_ddof_2": [1.632993], - "z_ddof_0": [0.816497], - } - compare_dicts(result, expected) - - @pytest.mark.filterwarnings("ignore:Determining|Resolving.*") def test_columns(constructor: Any) -> None: df = nw.from_native(constructor(data))