Repository navigation
[python-package] allow access to eval result attributes by name - #7161
Merged
Merged
Conversation
jameslamb
commented
Jul 12, 2026
| ] | ||
|
|
||
|
|
||
| class EvalResult(NamedTuple): |
Member
Author
There was a problem hiding this comment.
You know I'm usually very cautious about expanding the public API of the project... I think it is worth it for this case. This would allow users to get the full benefits of this change and eliminate positional references and tuple unpacking in their own code.
I'm especially thinking of user code that implements custom early stopping callbacks, and hyperparameter tuning frameworks like hyperopt and optuna.
Member
Author
|
Finally came back and finish this... I think this is ready for review. But no rush... it's ok with me if it doesn't make it into the v4.7.0 release. |
jameslamb
marked this pull request as ready for review
July 12, 2026 05:45
jameslamb
requested review from
StrikerRUS,
borchero,
guolinke,
jmoralez,
mayer79 and
shiyu1994
as code owners
July 12, 2026 05:45
borchero
approved these changes
Jul 14, 2026
borchero
left a comment
Member
There was a problem hiding this comment.
Cool, this will make code much more readable :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #6748
Wraps evaluation result tuples in the Python package in a
typing.NamedTuple, to allow named-attribute access to eval result tuples.Notes for Reviewers
Benefits of this change
mypyto catch bugscv())And provides all of these benefits for code that uses
lightgbm, especially code that touches evaluation results likeoptuna.Is this safe?
I think so. Any existing code treating these values (like the output of
Booster.eval_valid()) as Python tuples should continue to work exactly as they always have.As more evidence of this, this PR is passing CI without any changes to existing unit tests.
References
See https://snarky.ca/dont-use-named-tuples-in-new-apis/