Skip to content

Commit

Permalink
feat: consistently name selector parameters in validators
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Jan 14, 2025
1 parent 95e5459 commit c97c657
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/safeds/_validation/_check_column_is_numeric_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,19 @@ def _check_column_is_numeric(

def _check_columns_are_numeric(
table_or_schema: Table | Schema,
column_names: str | list[str],
selector: 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.
Check if the specified columns are numeric and raise an error if they are not. Missing columns are ignored.
Parameters
----------
table_or_schema:
The table or schema to check.
column_names:
The column names to check.
selector:
The columns to check.
operation:
The operation that is performed on the columns. This is used in the error message.
Expand All @@ -76,17 +74,17 @@ def _check_columns_are_numeric(

if isinstance(table_or_schema, Table):
table_or_schema = table_or_schema.schema
if isinstance(column_names, str):
column_names = [column_names]
if isinstance(selector, str):
selector = [selector]

Check warning on line 78 in src/safeds/_validation/_check_column_is_numeric_module.py

View check run for this annotation

Codecov / codecov/patch

src/safeds/_validation/_check_column_is_numeric_module.py#L78

Added line #L78 was not covered by tests

if len(column_names) > 1:
if len(selector) > 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
name for name in selector 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)
Expand Down

0 comments on commit c97c657

Please sign in to comment.