-
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.
Closes partially #754 Closes partially #977 ### Summary of Changes - Improve documentation for all methods of `Column`. - Add the option to specify the column type when calling the constructor. If omitted, it is still inferred from the data.
- Loading branch information
1 parent
ca1ce3d
commit 38dc89c
Showing
154 changed files
with
1,278 additions
and
947 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
46 changes: 46 additions & 0 deletions
46
src/safeds/_validation/_check_column_has_no_missing_values.py
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,46 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from safeds.exceptions import MissingValuesError | ||
|
||
if TYPE_CHECKING: | ||
from safeds.data.tabular.containers import Column | ||
|
||
|
||
def _check_column_has_no_missing_values( | ||
column: Column, | ||
*, | ||
other_columns: list[Column] | None = None, | ||
operation: str = "do an operation", | ||
) -> None: | ||
""" | ||
Check if the column has no missing values. | ||
Parameters | ||
---------- | ||
column: | ||
The column to check. | ||
other_columns: | ||
Other columns to check. This provides better error messages than checking each column individually. | ||
operation: | ||
The operation that is performed on the column. This is used in the error message. | ||
Raises | ||
------ | ||
MissingValuesError: | ||
If a has missing values. | ||
""" | ||
if other_columns is None: # pragma: no cover | ||
other_columns = [] | ||
|
||
columns = [column, *other_columns] | ||
missing_values_columns = [column.name for column in columns if column._series.has_nulls()] | ||
|
||
if missing_values_columns: | ||
message = _build_error_message(missing_values_columns, operation) | ||
raise MissingValuesError(message) from None | ||
|
||
|
||
def _build_error_message(missing_values_names: list[str], operation: str) -> str: | ||
return f"Tried to {operation} on columns with missing values {missing_values_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from safeds.exceptions import IndexOutOfBoundsError | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Sequence | ||
|
||
|
||
def _check_indices( | ||
sequence: Sequence, | ||
indices: int | list[int], | ||
*, | ||
allow_negative: bool = True, | ||
) -> None: | ||
""" | ||
Check if indices are valid for the provided sequence. | ||
Parameters | ||
---------- | ||
sequence: | ||
The sequence to check. | ||
indices: | ||
The indices to check. | ||
allow_negative: | ||
If negative indices are allowed. | ||
Raises | ||
------ | ||
IndexOutOfBoundsError: | ||
If the index is out of bounds. | ||
""" | ||
if isinstance(indices, int): | ||
indices = [indices] | ||
|
||
min_legal = -len(sequence) if allow_negative else 0 | ||
max_legal = len(sequence) - 1 | ||
|
||
illegal_indices = [index for index in indices if not min_legal <= index <= max_legal] | ||
if illegal_indices: | ||
message = _build_error_message(illegal_indices, min_legal, max_legal) | ||
raise IndexOutOfBoundsError(message) from None | ||
|
||
|
||
def _build_error_message(illegal_indices: list[int], min_legal: int, max_legal: int) -> str: | ||
return f"The indices {illegal_indices} are outside the legal interval [{min_legal}, {max_legal}]." |
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.