Fix with None input. (#10052)

This commit is contained in:
Jiaming Yuan
2024-02-20 22:34:22 +08:00
committed by GitHub
parent d37b83e8d9
commit 69a17d5114
4 changed files with 29 additions and 12 deletions

View File

@@ -1456,3 +1456,16 @@ def test_intercept() -> None:
result = reg.intercept_
assert result.dtype == np.float32
assert result[0] < 0.5
def test_fit_none() -> None:
with pytest.raises(TypeError, match="NoneType"):
xgb.XGBClassifier().fit(None, [0, 1])
X = rng.normal(size=4).reshape(2, 2)
with pytest.raises(ValueError, match="Invalid classes"):
xgb.XGBClassifier().fit(X, None)
with pytest.raises(ValueError, match="labels"):
xgb.XGBRegressor().fit(X, None)