Bug: mutable default argument evals_result=dict() in 27 model fit() methods
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 48.7k
- Forks
- 7.7k
- PR merge metrics
- No merged PRs in 30d
Description
Description
27 models in qlib/contrib/model/ use evals_result=dict() as a default argument in their fit() method. This is a well-known Python antipattern: the dict is created once at function definition time and shared across all calls, causing potential state leakage between separate fit() invocations.
The correct pattern (already used in gbdt.py and highfreq_gdbt_model.py) is:
def fit(self, dataset, evals_result=None):
if evals_result is None:
evals_result = {}
Affected files
All 27 files in qlib/contrib/model/ except gbdt.py and highfreq_gdbt_model.py.
I will submit a fix shortly.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the existing handling in qlib/contrib/model/gbdt.py and qlib/contrib/model/highfreq_gdbt_model.py. Review the other model files under qlib/contrib/model/ for the 27 affected fit() methods, then run the relevant model tests or checks available in the repository. Done means every affected method avoids shared default state and the model test suite remains passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100