Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
9fce6b8f
Unverified
Commit
9fce6b8f
authored
Mar 29, 2023
by
James Lamb
Committed by
GitHub
Mar 29, 2023
Browse files
[python-package] fix mypy errors about early stopping rounds (#5795)
parent
a5285985
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
python-package/lightgbm/engine.py
python-package/lightgbm/engine.py
+2
-2
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+8
-0
No files found.
python-package/lightgbm/engine.py
View file @
9fce6b8f
...
...
@@ -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"
,
...
...
tests/python_package_test/test_engine.py
View file @
9fce6b8f
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment