Skip to content

Bug: mutable default argument evals_result=dict() in 27 model fit() methods #2167

Description

@warren618

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions