-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: specify partial order in label encoder (#763)
Closes #639 ### Summary of Changes * Optionally specify a partial order of labels in the label encoder * Performance: Implement RangeScaler, StandardScaler, LabelEncoder with polars --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
74cc701
commit 6fbe537
Showing
60 changed files
with
672 additions
and
1,242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from safeds.exceptions import ColumnTypeError | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Container | ||
|
||
from safeds.data.tabular.containers import Table | ||
from safeds.data.tabular.typing import Schema | ||
|
||
|
||
def _check_columns_are_numeric( | ||
table_or_schema: Table | Schema, | ||
column_names: str | list[str], | ||
*, | ||
operation: str = "do a numeric operation", | ||
) -> None: | ||
""" | ||
Check if the columns with the specified names are numeric and raise an error if they are not. | ||
Missing columns are ignored. Use `_check_columns_exist` to check for missing columns. | ||
Parameters | ||
---------- | ||
table_or_schema: | ||
The table or schema to check. | ||
column_names: | ||
The column names to check. | ||
operation: | ||
The operation that is performed on the columns. This is used in the error message. | ||
Raises | ||
------ | ||
ColumnTypeError | ||
If a column exists but is not numeric. | ||
""" | ||
from safeds.data.tabular.containers import Table # circular import | ||
|
||
if isinstance(table_or_schema, Table): | ||
table_or_schema = table_or_schema.schema | ||
if isinstance(column_names, str): | ||
column_names = [column_names] | ||
|
||
if len(column_names) > 1: | ||
# Create a set for faster containment checks | ||
known_names: Container = set(table_or_schema.column_names) | ||
else: | ||
known_names = table_or_schema.column_names | ||
|
||
non_numeric_names = [ | ||
name for name in column_names if name in known_names and not table_or_schema.get_column_type(name).is_numeric | ||
] | ||
if non_numeric_names: | ||
message = _build_error_message(non_numeric_names, operation) | ||
raise ColumnTypeError(message) | ||
|
||
|
||
def _build_error_message(non_numeric_names: list[str], operation: str) -> str: | ||
return f"Tried to {operation} on non-numeric columns {non_numeric_names}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.