File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,26 @@ def test_imputation_shape():
7878 assert X_imputed .shape == (10 , 2 )
7979
8080
81+ @pytest .mark .parametrize ("strategy" , ["const" , 101 , None ])
82+ def test_imputation_error_invalid_strategy (strategy ):
83+ X = np .ones ((3 , 5 ))
84+ X [0 , 0 ] = np .nan
85+
86+ with pytest .raises (ValueError , match = str (strategy )):
87+ imputer = SimpleImputer (strategy = strategy )
88+ imputer .fit_transform (X )
89+
90+
91+ @pytest .mark .parametrize ("strategy" , ["mean" , "median" , "most_frequent" ])
92+ def test_imputation_deletion_warning (strategy ):
93+ X = np .ones ((3 , 5 ))
94+ X [:, 0 ] = np .nan
95+
96+ with pytest .warns (UserWarning , match = "Deleting" ):
97+ imputer = SimpleImputer (strategy = strategy , verbose = True )
98+ imputer .fit_transform (X )
99+
100+
81101def safe_median (arr , * args , ** kwargs ):
82102 # np.median([]) raises a TypeError for numpy >= 1.10.1
83103 length = arr .size if hasattr (arr , 'size' ) else len (arr )
You can’t perform that action at this time.
0 commit comments