diff --git a/src/safeds/data/tabular/containers/_tagged_table.py b/src/safeds/data/tabular/containers/_tagged_table.py index d06fa154b..67641cc1e 100644 --- a/src/safeds/data/tabular/containers/_tagged_table.py +++ b/src/safeds/data/tabular/containers/_tagged_table.py @@ -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 @@ -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 @@ -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: