File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,11 @@ def from_dataframe(
200200 DatasetDefaults .sampling_confidence_interval ,
201201 ** init_kwargs ,
202202 )
203+
204+ if target not in df :
205+ raise ValueError (
206+ f"{ target } column doesn't exist in data frame. Specify a valid one instead."
207+ )
203208
204209 if target_type is None :
205210 target_type = get_target_type (target , sampled_df , ** init_kwargs )
Original file line number Diff line number Diff line change 66import os
77from typing import Tuple
88import pandas as pd
9+ import pytest
910from ads .dataset .classification_dataset import BinaryClassificationDataset
1011from ads .dataset .dataset_with_target import ADSDatasetWithTarget
1112from ads .dataset .pipeline import TransformerPipeline
@@ -46,6 +47,16 @@ def test_accessor_with_target(self):
4647 assert isinstance (employees , BinaryClassificationDataset )
4748 self .assert_dataset (employees )
4849
50+ def test_accessor_with_target_error (self ):
51+ df = pd .read_csv (self .get_data_path ())
52+ wrong_column = "wrong_column"
53+ with pytest .raises (
54+ ValueError , match = f"{ wrong_column } column doesn't exist in data frame. Specify a valid one instead."
55+ ):
56+ employees = df .ads .dataset_with_target (
57+ target = wrong_column
58+ )
59+
4960 def assert_dataset (self , dataset ):
5061 assert isinstance (dataset .df , pd .DataFrame )
5162 assert isinstance (dataset .shape , Tuple )
You can’t perform that action at this time.
0 commit comments