[python-package] respect 'verbose' setting when using custom objective function (fixes #6014) #6428
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #6014.
Proposes changing the behavior of
Config::SetVerbosity()
when it's passedparams
that don't containverbose
orverbosity
. Instead of resetting the log level to INFO in those situations, as of this PR it would not modify the log level at all.See #6014 (comment) for an explanation of this.
Notes for Reviewers
How I tested this
Using the examples in #6014.
And I've added 2 new unit tests here (one for
lgb.train()
, one for thescikit-learn
interface) testing the behavior. These tests fail onmaster
.I also ran each of the Python test files one at a time, to be sure they weren't accidentally relying on log level state set by previous tests.
pytest tests/python_package_test/test_basic.py pytest tests/python_package_test/test_callback.py # etc., etc.
A note on usability
Prior to this change, from the perspective of the Python package it was sort of a hidden implementation detail that the logging level is a process-global variable.
LightGBM/include/LightGBM/utils/log.h
Lines 164 to 169 in fc788a5
Running
lgb.train(dtrain)
with all parameters at their defaults would always generate INFO-level logs.As of this change, passing
"verbosity"
throughparams
will now more obviously be a way to manipulate global state. For example:This might confuse some people at first, but I think it's a better behavior .The most important thing to know: as of this PR, passing
verbosity
throughparams
will always correctly set the log level.