Unverified Commit 9fce6b8f authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[python-package] fix mypy errors about early stopping rounds (#5795)

parent a5285985
......@@ -217,7 +217,7 @@ def train(
if "early_stopping_round" in params:
callbacks_set.add(
callback.early_stopping(
stopping_rounds=params["early_stopping_round"],
stopping_rounds=params["early_stopping_round"], # type: ignore[arg-type]
first_metric_only=first_metric_only,
verbose=_choose_param_value(
main_param_name="verbosity",
......@@ -708,7 +708,7 @@ def cv(
if "early_stopping_round" in params:
callbacks_set.add(
callback.early_stopping(
stopping_rounds=params["early_stopping_round"],
stopping_rounds=params["early_stopping_round"], # type: ignore[arg-type]
first_metric_only=first_metric_only,
verbose=_choose_param_value(
main_param_name="verbosity",
......
......@@ -4015,3 +4015,11 @@ def test_validate_features():
# check that disabling the check doesn't raise the error
bst.refit(df2, y, validate_features=False)
def test_train_raises_informative_error_for_params_of_wrong_type():
X, y = make_synthetic_regression()
params = {"early_stopping_round": "too-many"}
dtrain = lgb.Dataset(X, label=y)
with pytest.raises(lgb.basic.LightGBMError, match="Parameter early_stopping_round should be of type int, got \"too-many\""):
lgb.train(params, dtrain)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment