From 4b4322b15d3a9fc9ea92060e2803c32a1869e21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Gr=C3=A9us?= Date: Fri, 19 May 2023 14:14:42 +0200 Subject: [PATCH 1/3] test: Added test for `Table.remove_rows_with_outliers` to test multiple outliers in one column and outliers in two different columns --- .../_table/test_remove_rows_with_outliers.py | 144 +++++++++++++++++- 1 file changed, 138 insertions(+), 6 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py b/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py index 05b34f21f..d036ddcf9 100644 --- a/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py +++ b/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py @@ -13,7 +13,13 @@ "col3": [2, 3, 1], }, ), - 3, + Table( + { + "col1": ["A", "B", "C"], + "col2": [1.0, 2.0, 3.0], + "col3": [2, 3, 1], + }, + ), ), ( Table( @@ -36,20 +42,146 @@ "col3": [2, 3, 1, 1_000_000_000, 1, 1, 1, 1, 1, 1, 1, 1], }, ), - 11, + Table( + { + "col1": [ + "A", + "B", + "A", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + ], + "col2": [1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, None], + "col3": [2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1], + }, + ), ), ( + Table( + { + "col1": [ + "A", + "B", + "A", + "outlier_col3", + "a", + "a", + "a", + "a", + "a", + "a", + "outlier_col2", + "a", + ], + "col2": [1.0, 2.0, 3.0, 4.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1000.0, None], + "col3": [2, 3, 1, 1_000_000_000, 1, 1, 1, 1, 1, 1, 1, 1], + }, + ), + Table( + { + "col1": [ + "A", + "B", + "A", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + ], + "col2": [1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, None], + "col3": [2, 3, 1, 1, 1, 1, 1, 1, 1, 1], + }, + ), + ), + ( + Table( + { + "col1": [ + "A", + "B", + "A", + "positive_outlier", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "negative_outlier", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + ], + "col2": [1.0, 2.0, 3.0, 4.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, None, 1.0, 2.0, 1.0, 4.0, 1.0, 3.0, 1.0, 2.0, 1.0, 4.0, 1.0], + "col3": [2, 3, 1, 1_000_000_000_000, 1, 1, 1, 1, 1, 1, 1, 1, -1_000_000_000_000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + }, + ), + Table( + { + "col1": [ + "A", + "B", + "A", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + "a", + ], + "col2": [1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, None, 2.0, 1.0, 4.0, 1.0, 3.0, 1.0, 2.0, 1.0, 4.0, 1.0], + "col3": [2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + }, + ), + ), + ( + Table( + { + "col1": [], + "col2": [], + }, + ), Table( { "col1": [], "col2": [], }, ), - 0, ), ], - ids=["no outliers", "with outliers", "no rows"], + ids=["no outliers", "one outlier", "outliers in two different columns", "multiple outliers in one column", "no rows"], ) -def test_should_remove_rows_with_no_outliers(table: Table, expected: int) -> None: +def test_should_remove_rows_with_no_outliers(table: Table, expected: Table) -> None: updated_table = table.remove_rows_with_outliers() - assert updated_table.number_of_rows == expected + assert updated_table.schema == expected.schema + assert updated_table == expected From 158579637da800d8ad6f85b0e2f0208e92b22991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Gr=C3=A9us?= Date: Fri, 19 May 2023 14:17:33 +0200 Subject: [PATCH 2/3] refactor: Changed test `test_should_remove_rows_with_no_outliers` to be named `test_should_remove_rows_with_outliers` --- .../tabular/containers/_table/test_remove_rows_with_outliers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py b/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py index d036ddcf9..c344cc906 100644 --- a/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py +++ b/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py @@ -181,7 +181,7 @@ ], ids=["no outliers", "one outlier", "outliers in two different columns", "multiple outliers in one column", "no rows"], ) -def test_should_remove_rows_with_no_outliers(table: Table, expected: Table) -> None: +def test_should_remove_rows_with_outliers(table: Table, expected: Table) -> None: updated_table = table.remove_rows_with_outliers() assert updated_table.schema == expected.schema assert updated_table == expected From a58464c65aa48160632d8501435656762c6e02db Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 19 May 2023 12:23:01 +0000 Subject: [PATCH 3/3] style: apply automated linter fixes --- .../_table/test_remove_rows_with_outliers.py | 84 ++++++++++++++++++- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py b/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py index c344cc906..d699898e8 100644 --- a/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py +++ b/tests/safeds/data/tabular/containers/_table/test_remove_rows_with_outliers.py @@ -130,8 +130,56 @@ "a", "a", ], - "col2": [1.0, 2.0, 3.0, 4.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, None, 1.0, 2.0, 1.0, 4.0, 1.0, 3.0, 1.0, 2.0, 1.0, 4.0, 1.0], - "col3": [2, 3, 1, 1_000_000_000_000, 1, 1, 1, 1, 1, 1, 1, 1, -1_000_000_000_000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + "col2": [ + 1.0, + 2.0, + 3.0, + 4.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + None, + 1.0, + 2.0, + 1.0, + 4.0, + 1.0, + 3.0, + 1.0, + 2.0, + 1.0, + 4.0, + 1.0, + ], + "col3": [ + 2, + 3, + 1, + 1_000_000_000_000, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + -1_000_000_000_000, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + ], }, ), Table( @@ -159,7 +207,29 @@ "a", "a", ], - "col2": [1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, None, 2.0, 1.0, 4.0, 1.0, 3.0, 1.0, 2.0, 1.0, 4.0, 1.0], + "col2": [ + 1.0, + 2.0, + 3.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + None, + 2.0, + 1.0, + 4.0, + 1.0, + 3.0, + 1.0, + 2.0, + 1.0, + 4.0, + 1.0, + ], "col3": [2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], }, ), @@ -179,7 +249,13 @@ ), ), ], - ids=["no outliers", "one outlier", "outliers in two different columns", "multiple outliers in one column", "no rows"], + ids=[ + "no outliers", + "one outlier", + "outliers in two different columns", + "multiple outliers in one column", + "no rows", + ], ) def test_should_remove_rows_with_outliers(table: Table, expected: Table) -> None: updated_table = table.remove_rows_with_outliers()