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

fix: selectively ignore one warning instead of all warnings #235

Merged
merged 2 commits into from
Apr 21, 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
10 changes: 0 additions & 10 deletions src/safeds/data/tabular/transformation/_label_encoder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import annotations

import warnings
from typing import Any

from sklearn.preprocessing import OrdinalEncoder as sk_OrdinalEncoder

from safeds.data.tabular.containers import Table
Expand All @@ -12,13 +9,6 @@
)


def warn(*_: Any, **__: Any) -> None:
pass


warnings.warn = warn


# noinspection PyProtectedMember
class LabelEncoder(InvertibleTableTransformer):
"""The LabelEncoder encodes one or more given columns into labels."""
Expand Down
5 changes: 4 additions & 1 deletion src/safeds/ml/classical/_util_sklearn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Any

from safeds.data.tabular.containers import Table, TaggedTable
Expand Down Expand Up @@ -84,7 +85,9 @@ def predict(model: Any, dataset: Table, feature_names: list[str] | None, target_
result_set.columns = dataset.column_names

try:
predicted_target_vector = model.predict(dataset_df.values)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="X does not have valid feature names")
predicted_target_vector = model.predict(dataset_df.values)
result_set[target_name] = predicted_target_vector
return Table(result_set).tag_columns(target_name=target_name, feature_names=feature_names)
except ValueError as exception:
Expand Down