Skip to content

WIP: [python-package] allow access to eval result attributes by name#7161

Draft
jameslamb wants to merge 6 commits intomasterfrom
python/more-eval-tuples
Draft

WIP: [python-package] allow access to eval result attributes by name#7161
jameslamb wants to merge 6 commits intomasterfrom
python/more-eval-tuples

Conversation

@jameslamb
Copy link
Member

Closes #6748

Wraps evaluation result tuples in the Python package in a typing.NamedTuple, to allow named-attribute access to eval result tuples.

NOTE: If you see this, this isn't ready for review. Just opening to show I'm working on it and get feedback from CI.

Notes for Reviewers

Benefits of this change

  • simpler, less error-prone code
  • improves readability
  • improves the ability of type-checkers like mypy to catch bugs
  • eliminates awkward workarounds for different-sized tuples with and without a standard deviation (only added by cv())
  • tab completion when modifying the code

And provides all of these benefits for code that uses lightgbm, especially code that touches evaluation results like optuna.

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.

References

See https://snarky.ca/dont-use-named-tuples-in-new-apis/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python-package] factor out positional indexing for eval result tuples

1 participant