microsoft/qlib · error · ValueError

Unsupported reweighter type.

Error message

Unsupported reweighter type.

What it means

Raised by XGBModel.fit when the reweighter argument is neither None nor an instance of qlib's Reweighter. The wrapper only knows how to produce sample weights from a Reweighter object; any other type (dict, function, array) is rejected before xgb.train is called.

Source

Thrown at qlib/contrib/model/xgboost.py:54

            data_key=DataHandlerLP.DK_L,
        )
        x_train, y_train = df_train["feature"], df_train["label"]
        x_valid, y_valid = df_valid["feature"], df_valid["label"]

        # Lightgbm need 1D array as its label
        if y_train.values.ndim == 2 and y_train.values.shape[1] == 1:
            y_train_1d, y_valid_1d = np.squeeze(y_train.values), np.squeeze(y_valid.values)
        else:
            raise ValueError("XGBoost doesn't support multi-label training")

        if reweighter is None:
            w_train = None
            w_valid = None
        elif isinstance(reweighter, Reweighter):
            w_train = reweighter.reweight(df_train)
            w_valid = reweighter.reweight(df_valid)
        else:
            raise ValueError("Unsupported reweighter type.")

        dtrain = xgb.DMatrix(x_train.values, label=y_train_1d, weight=w_train)
        dvalid = xgb.DMatrix(x_valid.values, label=y_valid_1d, weight=w_valid)
        self.model = xgb.train(
            self._params,
            dtrain=dtrain,
            num_boost_round=num_boost_round,
            evals=[(dtrain, "train"), (dvalid, "valid")],
            early_stopping_rounds=early_stopping_rounds,
            verbose_eval=verbose_eval,
            evals_result=evals_result,
            **kwargs,
        )
        evals_result["train"] = list(evals_result["train"].values())[0]
        evals_result["valid"] = list(evals_result["valid"].values())[0]

    def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "test"):
        if self.model is None:

View on GitHub (pinned to 79633dd950)

Solutions

  1. Wrap your weighting logic in qlib's Reweighter (from qlib.data.dataset import Reweighter), e.g. Reweighter(name='feature', weight=df['my_weight']).
  2. Pass reweighter=None (or omit it) if you do not need sample weighting.
  3. If you built a custom class, make it a Reweighter subclass or just instantiate Reweighter with the right name/weight so isinstance() passes.

Example fix

# before
model.fit(dataset, reweighter={"weight": w})  # ValueError: Unsupported reweighter type.

# after
from qlib.data.dataset import Reweighter
rw = Reweighter(name="sample", weight=my_weight_df)  # proper Reweighter
model.fit(dataset, reweighter=rw)
Defensive patterns

Strategy: type-guard

Validate before calling

from qlib.data.dataset import Reweighter

if reweighter is not None and not isinstance(reweighter, Reweighter):
    raise TypeError("reweighter must be None or qlib Reweighter")
model.fit(dataset, reweighter=reweighter)

Type guard

from qlib.data.dataset import Reweighter

def is_valid_reweighter(rw) -> bool:
    return rw is None or isinstance(rw, Reweighter)

Prevention

When it happens

Trigger: Passing reweighter=some_dict, reweighter=np.array([...]), reweighter=lambda df: ..., or a custom class that duck-types reweight() but does not subclass/instantiate qlib.data.dataset.weight.Reweighted.

Common situations: Users coming from sklearn's sample_weight interface passing raw arrays; attempting custom weighting logic with a plain function instead of wrapping it in Reweighter; passing a serialized config dict instead of an instantiated object.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/c5d932a4e3a9ff0e. Report an issue: GitHub.