From bf3d7b9c06fab884095088d1131ff3e96d3b0ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 4 Jul 2023 16:31:59 +0200 Subject: [PATCH 01/11] Ignore UserWarning in OneHotEncoder test --- .../data/tabular/transformation/test_one_hot_encoder.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py index 57fbb1eeb..813d1bbdc 100644 --- a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py @@ -1,3 +1,5 @@ +import warnings + import pytest from safeds.data.tabular.containers import Table from safeds.data.tabular.transformation import OneHotEncoder @@ -138,7 +140,11 @@ def test_should_return_false_before_fitting(self) -> None: ) def test_should_return_true_after_fitting(self, table: Table) -> None: transformer = OneHotEncoder() - fitted_transformer = transformer.fit(table, None) + with warnings.catch_warnings(): + warnings.filterwarnings(action="ignore", category=UserWarning) + # nan values are technically "numerical", thus we get a UserWarning for the 2nd testcase. + # (Proper testing for the UserWarning is done in the TestFit class.) + fitted_transformer = transformer.fit(table, None) assert fitted_transformer.is_fitted() From aae3933c0ccfaf90724be3e74f5e14d576a2717c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 4 Jul 2023 16:56:40 +0200 Subject: [PATCH 02/11] Ignore first UserWarning in Imputer tests --- tests/safeds/data/tabular/transformation/test_imputer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/transformation/test_imputer.py b/tests/safeds/data/tabular/transformation/test_imputer.py index 73f667caa..6004d5007 100644 --- a/tests/safeds/data/tabular/transformation/test_imputer.py +++ b/tests/safeds/data/tabular/transformation/test_imputer.py @@ -1,3 +1,5 @@ +import warnings + import pytest from safeds.data.tabular.containers import Table from safeds.data.tabular.transformation import Imputer @@ -120,7 +122,10 @@ def test_should_raise_if_column_not_found(self, strategy: ImputerStrategy) -> No }, ) - transformer = Imputer(strategy).fit(table_to_fit, None) + with warnings.catch_warnings(): + warnings.filterwarnings(action="ignore", category=UserWarning) + # "Mode" strategy will raise a warning (as there is no single, most-common value in the 2nd testcase). + transformer = Imputer(strategy).fit(table_to_fit, None) table_to_transform = Table( { From 6f88e83790384d3c3cf6872cda1eb289ff11ed7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 4 Jul 2023 17:04:45 +0200 Subject: [PATCH 03/11] Only catch numerical warning in OneHotEncoder test --- .../data/tabular/transformation/test_one_hot_encoder.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py index 813d1bbdc..601f03594 100644 --- a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py @@ -141,7 +141,12 @@ def test_should_return_false_before_fitting(self) -> None: def test_should_return_true_after_fitting(self, table: Table) -> None: transformer = OneHotEncoder() with warnings.catch_warnings(): - warnings.filterwarnings(action="ignore", category=UserWarning) + warnings.filterwarnings( + action="ignore", + message=r"The columns col1 contain numerical data. The OneHotEncoder is designed to encode " + r"non-numerical values into numerical values", + category=UserWarning + ) # nan values are technically "numerical", thus we get a UserWarning for the 2nd testcase. # (Proper testing for the UserWarning is done in the TestFit class.) fitted_transformer = transformer.fit(table, None) From d48088a3dc26afaf2b910e96a856871e06138a8e Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:08:03 +0000 Subject: [PATCH 04/11] style: apply automated linter fixes --- .../data/tabular/transformation/test_one_hot_encoder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py index 601f03594..dba57b7d8 100644 --- a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py @@ -144,8 +144,8 @@ def test_should_return_true_after_fitting(self, table: Table) -> None: warnings.filterwarnings( action="ignore", message=r"The columns col1 contain numerical data. The OneHotEncoder is designed to encode " - r"non-numerical values into numerical values", - category=UserWarning + r"non-numerical values into numerical values", + category=UserWarning, ) # nan values are technically "numerical", thus we get a UserWarning for the 2nd testcase. # (Proper testing for the UserWarning is done in the TestFit class.) From 7621f87c4eaf3821a6f60a5ee51e7467a700263c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 4 Jul 2023 17:16:53 +0200 Subject: [PATCH 05/11] Fix filter regex syntax for OneHotEncoder warning --- .../data/tabular/transformation/test_one_hot_encoder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py index 601f03594..ed3ae8700 100644 --- a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py @@ -143,8 +143,8 @@ def test_should_return_true_after_fitting(self, table: Table) -> None: with warnings.catch_warnings(): warnings.filterwarnings( action="ignore", - message=r"The columns col1 contain numerical data. The OneHotEncoder is designed to encode " - r"non-numerical values into numerical values", + message="The columns \\[\'col1\'\\] contain numerical data. The OneHotEncoder is designed to encode " + "non-numerical values into numerical values", category=UserWarning ) # nan values are technically "numerical", thus we get a UserWarning for the 2nd testcase. From 2132c7e8e53925fc48b9e0da8c8340665f4f1dc7 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:20:22 +0000 Subject: [PATCH 06/11] style: apply automated linter fixes --- .../data/tabular/transformation/test_one_hot_encoder.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py index ed3ae8700..10f4a74db 100644 --- a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py @@ -143,9 +143,11 @@ def test_should_return_true_after_fitting(self, table: Table) -> None: with warnings.catch_warnings(): warnings.filterwarnings( action="ignore", - message="The columns \\[\'col1\'\\] contain numerical data. The OneHotEncoder is designed to encode " - "non-numerical values into numerical values", - category=UserWarning + message=( + "The columns \\['col1'\\] contain numerical data. The OneHotEncoder is designed to encode " + "non-numerical values into numerical values" + ), + category=UserWarning, ) # nan values are technically "numerical", thus we get a UserWarning for the 2nd testcase. # (Proper testing for the UserWarning is done in the TestFit class.) From 0d70a13af9e30828503566269846c60e177fe5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 4 Jul 2023 17:25:56 +0200 Subject: [PATCH 07/11] Ignore second USerWarning in Imputer tests --- tests/safeds/data/tabular/transformation/test_imputer.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/transformation/test_imputer.py b/tests/safeds/data/tabular/transformation/test_imputer.py index 6004d5007..425d901cf 100644 --- a/tests/safeds/data/tabular/transformation/test_imputer.py +++ b/tests/safeds/data/tabular/transformation/test_imputer.py @@ -285,7 +285,13 @@ def test_should_return_transformed_table( strategy: ImputerStrategy, expected: Table, ) -> None: - assert Imputer(strategy).fit_and_transform(table, column_names) == expected + with warnings.catch_warnings(): + warnings.filterwarnings( + action="ignore", + message=r"There are multiple most frequent values in a column given to the Imputer\..*", + category=UserWarning + ) + assert Imputer(strategy).fit_and_transform(table, column_names) == expected @pytest.mark.parametrize("strategy", strategies(), ids=lambda x: x.__class__.__name__) def test_should_not_change_original_table(self, strategy: ImputerStrategy) -> None: From ea1668a463ab860b9b38281fad4c303a105cec48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 4 Jul 2023 17:33:38 +0200 Subject: [PATCH 08/11] Unify warning filter style --- tests/safeds/data/tabular/transformation/test_imputer.py | 7 +++++-- .../data/tabular/transformation/test_one_hot_encoder.py | 6 ++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/safeds/data/tabular/transformation/test_imputer.py b/tests/safeds/data/tabular/transformation/test_imputer.py index 425d901cf..fbe4ef27d 100644 --- a/tests/safeds/data/tabular/transformation/test_imputer.py +++ b/tests/safeds/data/tabular/transformation/test_imputer.py @@ -123,8 +123,11 @@ def test_should_raise_if_column_not_found(self, strategy: ImputerStrategy) -> No ) with warnings.catch_warnings(): - warnings.filterwarnings(action="ignore", category=UserWarning) - # "Mode" strategy will raise a warning (as there is no single, most-common value in the 2nd testcase). + warnings.filterwarnings( + action="ignore", + message=r"There are multiple most frequent values in a column given to the Imputer\..*", + category=UserWarning + ) transformer = Imputer(strategy).fit(table_to_fit, None) table_to_transform = Table( diff --git a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py index 10f4a74db..810f9bd24 100644 --- a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py @@ -144,13 +144,11 @@ def test_should_return_true_after_fitting(self, table: Table) -> None: warnings.filterwarnings( action="ignore", message=( - "The columns \\['col1'\\] contain numerical data. The OneHotEncoder is designed to encode " - "non-numerical values into numerical values" + r"The columns .+ contain numerical data. The OneHotEncoder is designed to encode non-numerical " + r"values into numerical values" ), category=UserWarning, ) - # nan values are technically "numerical", thus we get a UserWarning for the 2nd testcase. - # (Proper testing for the UserWarning is done in the TestFit class.) fitted_transformer = transformer.fit(table, None) assert fitted_transformer.is_fitted() From 5c3bc75b0fc598a0560a510c1f487352c00c8701 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:36:03 +0000 Subject: [PATCH 09/11] style: apply automated linter fixes --- tests/safeds/data/tabular/transformation/test_imputer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/tabular/transformation/test_imputer.py b/tests/safeds/data/tabular/transformation/test_imputer.py index fbe4ef27d..ca7380e13 100644 --- a/tests/safeds/data/tabular/transformation/test_imputer.py +++ b/tests/safeds/data/tabular/transformation/test_imputer.py @@ -126,7 +126,7 @@ def test_should_raise_if_column_not_found(self, strategy: ImputerStrategy) -> No warnings.filterwarnings( action="ignore", message=r"There are multiple most frequent values in a column given to the Imputer\..*", - category=UserWarning + category=UserWarning, ) transformer = Imputer(strategy).fit(table_to_fit, None) @@ -292,7 +292,7 @@ def test_should_return_transformed_table( warnings.filterwarnings( action="ignore", message=r"There are multiple most frequent values in a column given to the Imputer\..*", - category=UserWarning + category=UserWarning, ) assert Imputer(strategy).fit_and_transform(table, column_names) == expected From f5e4b80de875568802ec9ad7ccf56c002543325b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Fri, 7 Jul 2023 09:12:11 +0200 Subject: [PATCH 10/11] Update tests/safeds/data/tabular/transformation/test_imputer.py Co-authored-by: Alexander <47296670+Marsmaennchen221@users.noreply.github.com> --- .../data/tabular/transformation/test_imputer.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/safeds/data/tabular/transformation/test_imputer.py b/tests/safeds/data/tabular/transformation/test_imputer.py index ca7380e13..4366894b2 100644 --- a/tests/safeds/data/tabular/transformation/test_imputer.py +++ b/tests/safeds/data/tabular/transformation/test_imputer.py @@ -122,12 +122,15 @@ def test_should_raise_if_column_not_found(self, strategy: ImputerStrategy) -> No }, ) - with warnings.catch_warnings(): - warnings.filterwarnings( - action="ignore", - message=r"There are multiple most frequent values in a column given to the Imputer\..*", - category=UserWarning, - ) + if isinstance(strategy, Imputer.Strategy.Mode): + with warnings.catch_warnings(): + warnings.filterwarnings( + action="ignore", + message=r"There are multiple most frequent values in a column given to the Imputer\..*", + category=UserWarning, + ) + transformer = Imputer(strategy).fit(table_to_fit, None) + else: transformer = Imputer(strategy).fit(table_to_fit, None) table_to_transform = Table( From 17ad3f562e770063958131c7334c3fcbf9ed84ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Fri, 7 Jul 2023 09:12:23 +0200 Subject: [PATCH 11/11] Update tests/safeds/data/tabular/transformation/test_imputer.py Co-authored-by: Alexander <47296670+Marsmaennchen221@users.noreply.github.com> --- .../data/tabular/transformation/test_imputer.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/safeds/data/tabular/transformation/test_imputer.py b/tests/safeds/data/tabular/transformation/test_imputer.py index 4366894b2..72426f34f 100644 --- a/tests/safeds/data/tabular/transformation/test_imputer.py +++ b/tests/safeds/data/tabular/transformation/test_imputer.py @@ -291,12 +291,15 @@ def test_should_return_transformed_table( strategy: ImputerStrategy, expected: Table, ) -> None: - with warnings.catch_warnings(): - warnings.filterwarnings( - action="ignore", - message=r"There are multiple most frequent values in a column given to the Imputer\..*", - category=UserWarning, - ) + if isinstance(strategy, Imputer.Strategy.Mode): + with warnings.catch_warnings(): + warnings.filterwarnings( + action="ignore", + message=r"There are multiple most frequent values in a column given to the Imputer\..*", + category=UserWarning, + ) + assert Imputer(strategy).fit_and_transform(table, column_names) == expected + else: assert Imputer(strategy).fit_and_transform(table, column_names) == expected @pytest.mark.parametrize("strategy", strategies(), ids=lambda x: x.__class__.__name__)