Skip to content

Commit

Permalink
feat: rename fit_transform to fit_and_transform (#119)
Browse files Browse the repository at this point in the history
Closes #112.

### Summary of Changes

Rename `fit_transform` to `fit_and_transform` to better indicate that
this method combines the two steps `fit` and `transform`.

---------

Co-authored-by: nikhilraj2003 <Nikhilraj@720>
Co-authored-by: Lars Reimann <mail@larsreimann.com>
Co-authored-by: dev-DTECH <deep64222@gmail.com>
  • Loading branch information
4 people committed Mar 30, 2023
1 parent 07b3062 commit 76a7112
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions tests/safeds/data/tabular/transformation/test_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_should_raise_if_not_fitted(self) -> None:
transformer.transform(table)


class TestFitTransform:
class TestFitAndTransform:
@pytest.mark.parametrize(
("table", "column_names", "strategy", "expected"),
[
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_should_raise_if_not_fitted(self) -> None:
transformer.transform(table)


class TestFitTransform:
class TestFitAndTransform:
@pytest.mark.parametrize(
("table", "column_names", "expected"),
[
Expand Down Expand Up @@ -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(
Expand All @@ -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(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_should_raise_if_not_fitted(self) -> None:
transformer.transform(table)


class TestFitTransform:
class TestFitAndTransform:
@pytest.mark.parametrize(
("table", "column_names", "expected"),
[
Expand Down Expand Up @@ -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(
Expand All @@ -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(
[
Expand Down

0 comments on commit 76a7112

Please sign in to comment.