[python-package] fix misleading redundant parameter warnings in Booster.refit()#7124
Open
arjunprakash027 wants to merge 8 commits intomicrosoft:masterfrom
Open
[python-package] fix misleading redundant parameter warnings in Booster.refit()#7124arjunprakash027 wants to merge 8 commits intomicrosoft:masterfrom
arjunprakash027 wants to merge 8 commits intomicrosoft:masterfrom
Conversation
jameslamb
requested changes
Feb 1, 2026
Collaborator
jameslamb
left a comment
There was a problem hiding this comment.
Thanks for all the investigation you've done so far! Leaving a blocking review, as I'd like the opportunity to look into this and suggest a different fix.
This patch with a double-nested if block inside a for loop and uses of inspect and locals() looks quite complex, and I'm worried it'd be difficult to modify correctly in the future.
Author
|
Thanks @jameslamb! |
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.
Fix Misleading Redundant Parameter Warnings in
Booster.refit()Fixes #6793
Problem
As discussed in #6793 , the
Booster.refit()method raises misleading warnings about redundant parameters being passed to the internalDatasetconstructor. The issue occurs when parameters likecategorical_featureorlabel_columnare stored in the Booster's internalparamsdictionary and then inadvertently passed both as keyword arguments and within theparamsdictionary toDataset(), triggering false-positive warnings.For additional context, see #6793 (comment)
Solution
This PR modifies
Booster.refit()to implement parameter routing:Parameter Inspection: Uses
inspect.signature()to dynamically identify which parameters belong to theDatasetconstructor by examiningDataset._lazy_init.Parameter Routing: Checks if a Dataset-related parameter (such as
categorical_featureorlabel_column) exists in the Booster's internalparamsbut has not been explicitly overridden by the user in therefit()call. When a parameter qualifies for routing (i.e., it's a Dataset parameter with a default value in therefit()signature), it is moved fromnew_paramsto the local variable scope for theDatasetconstructor. This ensures each parameter is passed exactly once to the internalDatasetobject, eliminating the redundant warning.I've tried to resolve the warning issue without changing the actual behavior of the refitting process.