Skip to content

Commit

Permalink
Merge branch 'main' into hyperparameter_choice
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann authored May 26, 2023
2 parents fa6f9bd + ca046c4 commit 1c200e9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 76 deletions.
3 changes: 0 additions & 3 deletions src/safeds/data/tabular/transformation/_imputer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from typing import Any

import pandas as pd
Expand Down Expand Up @@ -194,7 +193,6 @@ def get_names_of_added_columns(self) -> list[str]:
TransformerNotFittedError
If the transformer has not been fitted yet.
"""
warnings.warn("Imputer 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 @@ -232,7 +230,6 @@ def get_names_of_removed_columns(self) -> list[str]:
TransformerNotFittedError
If the transformer has not been fitted yet.
"""
warnings.warn("Imputer only changes data within columns, but does not remove any columns.", stacklevel=1)
if not self.is_fitted():
raise TransformerNotFittedError
return []
4 changes: 0 additions & 4 deletions src/safeds/data/tabular/transformation/_label_encoder.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 OrdinalEncoder as sk_OrdinalEncoder

from safeds.data.tabular.containers import Table
Expand Down Expand Up @@ -143,7 +141,6 @@ def get_names_of_added_columns(self) -> list[str]:
TransformerNotFittedError
If the transformer has not been fitted yet.
"""
warnings.warn("LabelEncoder 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 @@ -181,7 +178,6 @@ def get_names_of_removed_columns(self) -> list[str]:
TransformerNotFittedError
If the transformer has not been fitted yet.
"""
warnings.warn("LabelEncoder only changes data within columns, but does not remove any columns.", stacklevel=1)
if not self.is_fitted():
raise TransformerNotFittedError
return []
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 []
19 changes: 4 additions & 15 deletions tests/safeds/data/tabular/transformation/test_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ def test_should_not_change_original_table(self) -> None:

def test_get_names_of_added_columns(self) -> None:
transformer = Imputer(strategy=Imputer.Strategy.Constant(1))
with pytest.warns(
UserWarning,
match="Imputer 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 @@ -223,8 +220,7 @@ def test_get_names_of_added_columns(self) -> None:
},
)
transformer = transformer.fit(table, None)
with pytest.warns(UserWarning, match="Imputer 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 = Imputer(strategy=Imputer.Strategy.Constant(1))
Expand All @@ -241,10 +237,7 @@ def test_get_names_of_changed_columns(self) -> None:

def test_get_names_of_removed_columns(self) -> None:
transformer = Imputer(strategy=Imputer.Strategy.Constant(1))
with pytest.warns(
UserWarning,
match="Imputer 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 @@ -254,8 +247,4 @@ def test_get_names_of_removed_columns(self) -> None:
},
)
transformer = transformer.fit(table, None)
with pytest.warns(
UserWarning,
match="Imputer 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() == []
22 changes: 4 additions & 18 deletions tests/safeds/data/tabular/transformation/test_label_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ def test_should_not_change_original_table(self) -> None:

def test_get_names_of_added_columns(self) -> None:
transformer = LabelEncoder()
with pytest.warns(
UserWarning,
match="LabelEncoder 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 @@ -151,11 +148,7 @@ def test_get_names_of_added_columns(self) -> None:
},
)
transformer = transformer.fit(table, None)
with pytest.warns(
UserWarning,
match="LabelEncoder 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 = LabelEncoder()
Expand All @@ -171,10 +164,7 @@ def test_get_names_of_changed_columns(self) -> None:

def test_get_names_of_removed_columns(self) -> None:
transformer = LabelEncoder()
with pytest.warns(
UserWarning,
match="LabelEncoder 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 @@ -183,11 +173,7 @@ def test_get_names_of_removed_columns(self) -> None:
},
)
transformer = transformer.fit(table, None)
with pytest.warns(
UserWarning,
match="LabelEncoder 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
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 1c200e9

Please sign in to comment.