[python-package] fix misleading redundant parameter warnings in Booster.refit() #7124
+11
−0
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.