Skip to content

Commit

Permalink
style: apply automated linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
megalinter-bot committed Nov 16, 2023
1 parent 106a917 commit 5516852
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/safeds/data/tabular/containers/_tagged_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def add_columns_as_features(self, columns: list[Column] | Table) -> TaggedTable:
super().add_columns(columns),
target_name=self.target.name,
feature_names=self.features.column_names
+ [col.name for col in (columns.to_columns() if isinstance(columns, Table) else columns)],
+ [col.name for col in (columns.to_columns() if isinstance(columns, Table) else columns)],
)

# ------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -686,8 +686,8 @@ def replace_column(self, old_column_name: str, new_columns: list[Column]) -> Tag
self.features.column_names
if old_column_name not in self.features.column_names
else self.features.column_names[: self.features.column_names.index(old_column_name)]
+ [col.name for col in new_columns]
+ self.features.column_names[self.features.column_names.index(old_column_name) + 1:]
+ [col.name for col in new_columns]
+ self.features.column_names[self.features.column_names.index(old_column_name) + 1 :]
),
)

Expand Down Expand Up @@ -747,7 +747,7 @@ def slice_rows(
def sort_columns(
self,
comparator: Callable[[Column, Column], int] = lambda col1, col2: (col1.name > col2.name)
- (col1.name < col2.name),
- (col1.name < col2.name),
) -> TaggedTable:
"""
Sort the columns of a `TaggedTable` with the given comparator and return a new `TaggedTable`.
Expand Down
8 changes: 3 additions & 5 deletions src/safeds/data/tabular/transformation/_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ def fit(self, table: Table, column_names: list[str] | None) -> Imputer:
multiple_most_frequent[name] = table.get_column(name).mode()
if len(multiple_most_frequent) > 0:
warnings.warn(
(
"There are multiple most frequent values in a column given to the Imputer.\nThe lowest values"
" are being chosen in this cases. The following columns have multiple most frequent"
f" values:\n{multiple_most_frequent}"
),
"There are multiple most frequent values in a column given to the Imputer.\nThe lowest values"
" are being chosen in this cases. The following columns have multiple most frequent"
f" values:\n{multiple_most_frequent}",
UserWarning,
stacklevel=2,
)
Expand Down
9 changes: 3 additions & 6 deletions src/safeds/data/tabular/transformation/_label_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ def fit(self, table: Table, column_names: list[str] | None) -> LabelEncoder:

if table.keep_only_columns(column_names).remove_columns_with_non_numerical_values().number_of_columns > 0:
warnings.warn(
(
"The columns"
f" {table.keep_only_columns(column_names).remove_columns_with_non_numerical_values().column_names} contain"
" numerical data. The LabelEncoder is designed to encode non-numerical values into numerical"
" values"
),
"The columns"
f" {table.keep_only_columns(column_names).remove_columns_with_non_numerical_values().column_names} contain"
" numerical data. The LabelEncoder is designed to encode non-numerical values into numerical values",
UserWarning,
stacklevel=2,
)
Expand Down
9 changes: 3 additions & 6 deletions src/safeds/data/tabular/transformation/_one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,9 @@ def fit(self, table: Table, column_names: list[str] | None) -> OneHotEncoder:
> 0
):
warnings.warn(
(
"The columns"
f" {table._as_table().keep_only_columns(column_names).remove_columns_with_non_numerical_values().column_names} contain"
" numerical data. The OneHotEncoder is designed to encode non-numerical values into numerical"
" values"
),
"The columns"
f" {table._as_table().keep_only_columns(column_names).remove_columns_with_non_numerical_values().column_names} contain"
" numerical data. The OneHotEncoder is designed to encode non-numerical values into numerical values",
UserWarning,
stacklevel=2,
)
Expand Down
28 changes: 10 additions & 18 deletions src/safeds/ml/classical/_util_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ def fit(model: Any, tagged_table: TaggedTable) -> None:
if len(non_numerical_column_names) != 0:
raise NonNumericColumnError(
str(non_numerical_column_names),
(
"You can use the LabelEncoder or OneHotEncoder to transform your non-numerical data to numerical"
" data.\nThe OneHotEncoder should be used if you work with nominal data. If your data contains too many"
" different values\nor is ordinal, you should use the LabelEncoder."
),
"You can use the LabelEncoder or OneHotEncoder to transform your non-numerical data to numerical"
" data.\nThe OneHotEncoder should be used if you work with nominal data. If your data contains too many"
" different values\nor is ordinal, you should use the LabelEncoder.",
)

null_containing_column_names = set(tagged_table.features.column_names) - set(
Expand All @@ -65,10 +63,8 @@ def fit(model: Any, tagged_table: TaggedTable) -> None:
if len(null_containing_column_names) != 0:
raise MissingValuesColumnError(
str(null_containing_column_names),
(
"You can use the Imputer to replace the missing values based on different strategies.\nIf you want to"
" remove the missing values entirely you can use the method `Table.remove_rows_with_missing_values`."
),
"You can use the Imputer to replace the missing values based on different strategies.\nIf you want to"
" remove the missing values entirely you can use the method `Table.remove_rows_with_missing_values`.",
)

try:
Expand Down Expand Up @@ -138,11 +134,9 @@ def predict(model: Any, dataset: Table, feature_names: list[str] | None, target_
if len(non_numerical_column_names) != 0:
raise NonNumericColumnError(
str(non_numerical_column_names),
(
"You can use the LabelEncoder or OneHotEncoder to transform your non-numerical data to numerical"
" data.\nThe OneHotEncoder should be used if you work with nominal data. If your data contains too many"
" different values\nor is ordinal, you should use the LabelEncoder.\n"
),
"You can use the LabelEncoder or OneHotEncoder to transform your non-numerical data to numerical"
" data.\nThe OneHotEncoder should be used if you work with nominal data. If your data contains too many"
" different values\nor is ordinal, you should use the LabelEncoder.\n",
)

null_containing_column_names = set(dataset.keep_only_columns(feature_names).column_names) - set(
Expand All @@ -151,10 +145,8 @@ def predict(model: Any, dataset: Table, feature_names: list[str] | None, target_
if len(null_containing_column_names) != 0:
raise MissingValuesColumnError(
str(null_containing_column_names),
(
"You can use the Imputer to replace the missing values based on different strategies.\nIf you want to"
" remove the missing values entirely you can use the method `Table.remove_rows_with_missing_values`."
),
"You can use the Imputer to replace the missing values based on different strategies.\nIf you want to"
" remove the missing values entirely you can use the method `Table.remove_rows_with_missing_values`.",
)

dataset_df = dataset.keep_only_columns(feature_names)._data
Expand Down

0 comments on commit 5516852

Please sign in to comment.