From a977a374dcefda5f7bbf153865a74f0a658f99e7 Mon Sep 17 00:00:00 2001 From: dev-DTECH Date: Thu, 30 Mar 2023 11:40:51 +0530 Subject: [PATCH] Refactoring fit_transform to fit_and_transform --- .../data/tabular/transformation/_table_transformer.py | 2 +- tests/safeds/data/tabular/transformation/test_imputer.py | 6 +++--- .../data/tabular/transformation/test_label_encoder.py | 4 ++-- .../data/tabular/transformation/test_one_hot_encoder.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/safeds/data/tabular/transformation/_table_transformer.py b/src/safeds/data/tabular/transformation/_table_transformer.py index b939fe1e9..9ad4d1236 100644 --- a/src/safeds/data/tabular/transformation/_table_transformer.py +++ b/src/safeds/data/tabular/transformation/_table_transformer.py @@ -52,7 +52,7 @@ def transform(self, table: Table) -> Table: If the transformer has not been fitted yet. """ - def fit_transform(self, table: Table, column_names: Optional[list[str]] = None) -> Table: + def fit_and_transform(self, table: Table, column_names: Optional[list[str]] = None) -> Table: """ Learn a transformation for a set of columns in a table and apply the learned transformation to the same table. If you also need the fitted transformer, use `fit` and `transform` separately. diff --git a/tests/safeds/data/tabular/transformation/test_imputer.py b/tests/safeds/data/tabular/transformation/test_imputer.py index 84d039571..bcb4eda1d 100644 --- a/tests/safeds/data/tabular/transformation/test_imputer.py +++ b/tests/safeds/data/tabular/transformation/test_imputer.py @@ -145,7 +145,7 @@ class TestFitTransform: def test_should_return_transformed_table( self, table: Table, column_names: Optional[list[str]], strategy: ImputerStrategy, expected: Table ) -> None: - assert Imputer(strategy).fit_transform(table, column_names) == expected + assert Imputer(strategy).fit_and_transform(table, column_names) == expected def test_should_raise_if_strategy_is_mode_but_multiple_values_are_most_frequent(self) -> None: table = Table.from_columns( @@ -155,7 +155,7 @@ def test_should_raise_if_strategy_is_mode_but_multiple_values_are_most_frequent( ) with pytest.raises(IndexError): - Imputer(Imputer.Strategy.Mode()).fit_transform(table) + Imputer(Imputer.Strategy.Mode()).fit_and_transform(table) def test_should_not_change_original_table(self) -> None: table = Table.from_columns( @@ -164,7 +164,7 @@ def test_should_not_change_original_table(self) -> None: ] ) - Imputer(strategy=Imputer.Strategy.Constant(1)).fit_transform(table) + Imputer(strategy=Imputer.Strategy.Constant(1)).fit_and_transform(table) expected = Table.from_columns( [ diff --git a/tests/safeds/data/tabular/transformation/test_label_encoder.py b/tests/safeds/data/tabular/transformation/test_label_encoder.py index e29e74742..4a9f328a0 100644 --- a/tests/safeds/data/tabular/transformation/test_label_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_label_encoder.py @@ -100,7 +100,7 @@ class TestFitTransform: def test_should_return_transformed_table( self, table: Table, column_names: Optional[list[str]], expected: Table ) -> None: - assert LabelEncoder().fit_transform(table, column_names) == expected + assert LabelEncoder().fit_and_transform(table, column_names) == expected def test_should_not_change_original_table(self) -> None: table = Table.from_columns( @@ -109,7 +109,7 @@ def test_should_not_change_original_table(self) -> None: ] ) - LabelEncoder().fit_transform(table) + LabelEncoder().fit_and_transform(table) expected = Table.from_columns( [ 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 061d6d6b9..bdb73c98c 100644 --- a/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py +++ b/tests/safeds/data/tabular/transformation/test_one_hot_encoder.py @@ -104,7 +104,7 @@ class TestFitTransform: def test_should_return_transformed_table( self, table: Table, column_names: Optional[list[str]], expected: Table ) -> None: - assert OneHotEncoder().fit_transform(table, column_names) == expected + assert OneHotEncoder().fit_and_transform(table, column_names) == expected def test_should_not_change_original_table(self) -> None: table = Table.from_columns( @@ -113,7 +113,7 @@ def test_should_not_change_original_table(self) -> None: ] ) - OneHotEncoder().fit_transform(table) + OneHotEncoder().fit_and_transform(table) expected = Table.from_columns( [