Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename fit_transform to fit_and_transform #119

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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