Skip to content

Commit 20456f4

Browse files
committed
add tests for warnings and errors catch
1 parent 94d7964 commit 20456f4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sklearn/tests/test_impute.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
81101
def 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)

0 commit comments

Comments
 (0)