Skip to content

Commit

Permalink
feat: Explicitly throw UnknownColumnNameError in `TaggedTable._from…
Browse files Browse the repository at this point in the history
…_table` (#334)

Closes #333.

### Summary of Changes

Explicitly throw `UnknownColumnNameError` in `TaggedTable._from_table`
for a more readable stacktrace.
Document when this exception is thrown.

Co-authored-by: Alexander <47296670+Marsmaennchen221@users.noreply.github.com>
  • Loading branch information
zzril and Marsmaennchen221 committed Jun 9, 2023
1 parent 57b0572 commit 498999f
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 498999f

Please sign in to comment.