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

feat: Explicitly throw UnknownColumnNameError in TaggedTable._from_table #334

Merged
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
9 changes: 7 additions & 2 deletions src/safeds/data/tabular/containers/_tagged_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import TYPE_CHECKING

from safeds.data.tabular.containers import Column, Table
from safeds.exceptions import UnknownColumnNameError

if TYPE_CHECKING:
from collections.abc import Mapping, Sequence
Expand Down Expand Up @@ -67,6 +68,8 @@ def _from_table(

Raises
------
UnknownColumnNameError
If target_name matches none of the column names.
ValueError
If the target column is also a feature column.
ValueError
Expand All @@ -78,11 +81,13 @@ def _from_table(
>>> table = Table({"col1": ["a", "b", "c", "a"], "col2": [1, 2, 3, 4]})
>>> tagged_table = TaggedTable._from_table(table, "col2", ["col1"])
"""
if target_name not in table.column_names:
raise UnknownColumnNameError([target_name])

# If no feature names are specified, use all columns except the target column
if feature_names is None:
feature_names = table.column_names
if target_name in feature_names:
feature_names.remove(target_name)
feature_names.remove(target_name)

# Validate inputs
if target_name in feature_names:
Expand Down