[BUG] Fix validate_callback_data flagging local variables as missing args - #595
Open
sumitjhadev wants to merge 1 commit into
Open
[BUG] Fix validate_callback_data flagging local variables as missing args#595sumitjhadev wants to merge 1 commit into
sumitjhadev wants to merge 1 commit into
Conversation
sumitjhadev
force-pushed
the
fix/callback-local-vars
branch
from
August 31, 2026 10:02
8438a2a to
5602279
Compare
…args method.__code__.co_varnames includes every local variable declared inside a function body, not just its formal parameters. Since validate_callback_data used co_varnames directly to determine which keys a callback needs pulled from the training loop's variables dict, any custom CallBack.on_loop_start or on_loop_end that declares its own local variables was incorrectly flagged as a missing argument and raised: AssertionError: CallBack cannot reference: step_threshold Fix: slice co_varnames down to co_argcount, which isolates the function's formal parameters from its internal locals. Built-in callbacks (Deviance/Diffs/Accuracy) are unaffected since none of them declare local variables, which is also why this had gone unnoticed. Adds pygam/tests/test_callbacks.py with a unit test reproducing the original AssertionError, a check that missing genuine arguments are still caught, and an end-to-end GAM.fit() using a custom callback with a local variable. Testing: pytest -s pygam/tests -> 165 passed, 1 skipped, matching main's baseline.
sumitjhadev
force-pushed
the
fix/callback-local-vars
branch
from
August 31, 2026 10:16
5602279 to
dea59e3
Compare
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.
method.code.co_varnames includes every local variable declared inside a function body, not just its formal parameters. Since validate_callback_data used co_varnames directly to determine which keys a callback needs pulled from the training loop's variables dict, any custom CallBack.on_loop_start or on_loop_end that declares its own local variables was incorrectly flagged as a missing argument and raised: AssertionError: CallBack cannot reference: step_threshold
Fix: slice co_varnames down to co_argcount, which isolates the function's formal parameters from its internal locals. Built-in callbacks (Deviance/Diffs/Accuracy) are unaffected since none of them declare local variables, which is also why this had gone unnoticed.
Adds pygam/tests/test_callbacks.py with a unit test reproducing the original AssertionError, a check that missing genuine arguments are still caught, and an end-to-end GAM.fit() using a custom callback with a local variable.
Testing: pytest -s pygam/tests -> 165 passed, 1 skipped, matching main's baseline.
Fixes #596