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(
200
200
DatasetDefaults .sampling_confidence_interval ,
201
201
** init_kwargs ,
202
202
)
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
+ )
203
208
204
209
if target_type is None :
205
210
target_type = get_target_type (target , sampled_df , ** init_kwargs )
Original file line number Diff line number Diff line change 6
6
import os
7
7
from typing import Tuple
8
8
import pandas as pd
9
+ import pytest
9
10
from ads .dataset .classification_dataset import BinaryClassificationDataset
10
11
from ads .dataset .dataset_with_target import ADSDatasetWithTarget
11
12
from ads .dataset .pipeline import TransformerPipeline
@@ -46,6 +47,16 @@ def test_accessor_with_target(self):
46
47
assert isinstance (employees , BinaryClassificationDataset )
47
48
self .assert_dataset (employees )
48
49
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
+
49
60
def assert_dataset (self , dataset ):
50
61
assert isinstance (dataset .df , pd .DataFrame )
51
62
assert isinstance (dataset .shape , Tuple )
You can’t perform that action at this time.
0 commit comments