{"record":{"id":"9ef3666bfeea14bc","repo":"microsoft/qlib","slug":"unsupported-reweighter-type-9ef366","errorCode":null,"errorMessage":"Unsupported reweighter type.","messagePattern":"Unsupported reweighter type\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/model/gbdt.py","lineNumber":53,"sourceCode":"        for key in [\"train\", \"valid\"]:\n            if key in dataset.segments:\n                df = dataset.prepare(key, col_set=[\"feature\", \"label\"], data_key=DataHandlerLP.DK_L)\n                if df.empty:\n                    raise ValueError(\"Empty data from dataset, please check your dataset config.\")\n                x, y = df[\"feature\"], df[\"label\"]\n\n                # Lightgbm need 1D array as its label\n                if y.values.ndim == 2 and y.values.shape[1] == 1:\n                    y = np.squeeze(y.values)\n                else:\n                    raise ValueError(\"LightGBM doesn't support multi-label training\")\n\n                if reweighter is None:\n                    w = None\n                elif isinstance(reweighter, Reweighter):\n                    w = reweighter.reweight(df)\n                else:\n                    raise ValueError(\"Unsupported reweighter type.\")\n                ds_l.append((lgb.Dataset(x.values, label=y, weight=w, free_raw_data=False), key))\n        return ds_l\n\n    def fit(\n        self,\n        dataset: DatasetH,\n        num_boost_round=None,\n        early_stopping_rounds=None,\n        verbose_eval=20,\n        evals_result=None,\n        reweighter=None,\n        **kwargs,\n    ):\n        if evals_result is None:\n            evals_result = {}  # in case of unsafety of Python default values\n        ds_l = self._prepare_data(dataset, reweighter)\n        ds, names = list(zip(*ds_l))\n        early_stopping_callback = lgb.early_stopping(","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/gbdt.py#L35-L71","documentation":"Thrown by LGBModel._prepare_data when the reweighter argument is neither None nor a qlib.model.base.Reweighter instance. The API accepts only these two forms; passing arrays, callables, or duck-typed objects fails before the lgb.Dataset is built.","triggerScenarios":"model.fit(dataset, reweighter=np.array([...])) or reweighter=some_function; a custom class implementing reweight() without subclassing Reweighter.","commonSituations":"Coming from sklearn's sample_weight convention; writing a custom weighting scheme unaware of the Reweighter base class.","solutions":["Subclass qlib.model.base.Reweighter and implement reweight(self, df) -> pd.Series","Pass reweighter=None when no weighting is needed"],"exampleFix":"# before\nmodel.fit(dataset, reweighter=np.ones(n))\n\n# after\nfrom qlib.model.base import Reweighter\n\nclass MyReweighter(Reweighter):\n    def reweight(self, df):\n        return pd.Series(1.0, index=df.index)\n\nmodel.fit(dataset, reweighter=MyReweighter())","handlingStrategy":"type-guard","validationCode":"from qlib.model.base import Reweighter\nassert reweighter is None or isinstance(reweighter, Reweighter)","typeGuard":"from qlib.model.base import Reweighter\n\ndef is_valid_reweighter(r) -> bool:\n    return r is None or isinstance(r, Reweighter)","tryCatchPattern":null,"preventionTips":["Subclass Reweighter for custom weighting schemes","Never pass weight arrays directly to fit"],"tags":["lightgbm","reweighter","type-check","qlib"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}