Skip to content

Conversation

@FrancoisPgm
Copy link

Following what was discussed in the callback API meeting, this PR uses the _fit_context private decorator to initialize and clean-up the CallbackContext objects, using a context manager. A public decorator that only does the callback context management is also added for 3rd party devs who want callbacks without the param validation in _fit_context. And the callback context attribute is renamed.

Since the callback context is initialised outside of the fit function, its max_iter attribute must be set outside of the init function. Right now it is done simply by assigning a value to the attribute, it could be done through a dedicated setter method, or in eval_on_fit_begin.

Some tests are refactored to use _from_estimator to instantiate the callback contexts.

Some tests are added, one for the new public decorator, and one for estimators that uses their parent's fit. The specific problem in the latter case was that in that case the decorator is called twice, meaning some actions must be wrapped in a try except, like the deletion of the _callback_fit_ctx attribute, otherwise trying to delete the second time raises an error.

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: f4ce67c. Link to the linter CI: here

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants