Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/323-remove-warnings-from-transfo…
Browse files Browse the repository at this point in the history
…rmer-methods-added-in-304' into 323-remove-warnings-from-transformer-methods-added-in-304
  • Loading branch information
sibre28 committed May 26, 2023
2 parents 567286e + dcf9203 commit 0f84124
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
2 changes: 0 additions & 2 deletions src/safeds/data/tabular/transformation/_one_hot_encoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from collections import Counter
from typing import Any

Expand Down Expand Up @@ -284,7 +283,6 @@ def get_names_of_changed_columns(self) -> list[str]:
TransformerNotFittedError
If the transformer has not been fitted yet.
"""
warnings.warn("OneHotEncoder only removes and adds, but does not change any columns.", stacklevel=1)
if not self.is_fitted():
raise TransformerNotFittedError
return []
Expand Down
4 changes: 0 additions & 4 deletions src/safeds/data/tabular/transformation/_range_scaler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import warnings

from sklearn.preprocessing import MinMaxScaler as sk_MinMaxScaler

from safeds.data.tabular.containers import Table
Expand Down Expand Up @@ -157,7 +155,6 @@ def get_names_of_added_columns(self) -> list[str]:
TransformerNotFittedError
If the transformer has not been fitted yet.
"""
warnings.warn("RangeScaler only changes data within columns, but does not add any columns.", stacklevel=1)
if not self.is_fitted():
raise TransformerNotFittedError
return []
Expand Down Expand Up @@ -195,7 +192,6 @@ def get_names_of_removed_columns(self) -> list[str]:
TransformerNotFittedError
If the transformer has not been fitted yet.
"""
warnings.warn("RangeScaler only changes data within columns, but does not remove any columns.", stacklevel=1)
if not self.is_fitted():
raise TransformerNotFittedError
return []
20 changes: 8 additions & 12 deletions tests/safeds/data/tabular/transformation/test_one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,16 @@ def test_get_names_of_added_columns(self) -> None:

def test_get_names_of_changed_columns(self) -> None:
transformer = OneHotEncoder()
with pytest.warns(
UserWarning,
match="OneHotEncoder only removes and adds, but does not change any columns.",
), pytest.raises(TransformerNotFittedError):
with pytest.raises(TransformerNotFittedError):
transformer.get_names_of_changed_columns()

with pytest.warns(UserWarning, match="OneHotEncoder only removes and adds, but does not change any columns."):
table = Table(
{
"a": ["b"],
},
)
transformer = transformer.fit(table, None)
assert transformer.get_names_of_changed_columns() == []
table = Table(
{
"a": ["b"],
},
)
transformer = transformer.fit(table, None)
assert transformer.get_names_of_changed_columns() == []

def test_get_names_of_removed_columns(self) -> None:
transformer = OneHotEncoder()
Expand Down
22 changes: 4 additions & 18 deletions tests/safeds/data/tabular/transformation/test_range_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ def test_should_not_change_original_table(self) -> None:

def test_get_names_of_added_columns(self) -> None:
transformer = RangeScaler()
with pytest.warns(
UserWarning,
match="RangeScaler only changes data within columns, but does not add any columns.",
), pytest.raises(TransformerNotFittedError):
with pytest.raises(TransformerNotFittedError):
transformer.get_names_of_added_columns()

table = Table(
Expand All @@ -198,11 +195,7 @@ def test_get_names_of_added_columns(self) -> None:
},
)
transformer = transformer.fit(table, None)
with pytest.warns(
UserWarning,
match="RangeScaler only changes data within columns, but does not add any columns.",
):
assert transformer.get_names_of_added_columns() == []
assert transformer.get_names_of_added_columns() == []

def test_get_names_of_changed_columns(self) -> None:
transformer = RangeScaler()
Expand All @@ -218,10 +211,7 @@ def test_get_names_of_changed_columns(self) -> None:

def test_get_names_of_removed_columns(self) -> None:
transformer = RangeScaler()
with pytest.warns(
UserWarning,
match="RangeScaler only changes data within columns, but does not remove any columns.",
), pytest.raises(TransformerNotFittedError):
with pytest.raises(TransformerNotFittedError):
transformer.get_names_of_removed_columns()

table = Table(
Expand All @@ -230,11 +220,7 @@ def test_get_names_of_removed_columns(self) -> None:
},
)
transformer = transformer.fit(table, None)
with pytest.warns(
UserWarning,
match="RangeScaler only changes data within columns, but does not remove any columns.",
):
assert transformer.get_names_of_removed_columns() == []
assert transformer.get_names_of_removed_columns() == []


class TestInverseTransform:
Expand Down

0 comments on commit 0f84124

Please sign in to comment.