{"record":{"id":"18cd37d787d57494","repo":"microsoft/qlib","slug":"the-type-of-dataset-is-not-dataseth-instead-of","errorCode":null,"errorMessage":"The type of dataset is not DatasetH instead of {:}","messagePattern":"The type of dataset is not DatasetH instead of (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/workflow/record_temp.py","lineNumber":28,"sourceCode":"from ...contrib.eva.alpha import calc_ic\nfrom ...workflow.record_temp import RecordTemp\nfrom ...workflow.record_temp import SignalRecord\nfrom ...data import dataset as qlib_dataset\nfrom ...log import get_module_logger\n\nlogger = get_module_logger(\"workflow\", logging.INFO)\n\n\nclass MultiSegRecord(RecordTemp):\n    \"\"\"\n    This is the multiple segments signal record class that generates the signal prediction.\n    This class inherits the ``RecordTemp`` class.\n    \"\"\"\n\n    def __init__(self, model, dataset, recorder=None):\n        super().__init__(recorder=recorder)\n        if not isinstance(dataset, qlib_dataset.DatasetH):\n            raise ValueError(\"The type of dataset is not DatasetH instead of {:}\".format(type(dataset)))\n        self.model = model\n        self.dataset = dataset\n\n    def generate(self, segments: Dict[Text, Any], save: bool = False):\n        for key, segment in segments.items():\n            predics = self.model.predict(self.dataset, segment)\n            if isinstance(predics, pd.Series):\n                predics = predics.to_frame(\"score\")\n            labels = self.dataset.prepare(\n                segments=segment, col_set=\"label\", data_key=qlib_dataset.handler.DataHandlerLP.DK_R\n            )\n            # Compute the IC and Rank IC\n            ic, ric = calc_ic(predics.iloc[:, 0], labels.iloc[:, 0])\n            results = {\"all-IC\": ic, \"mean-IC\": ic.mean(), \"all-Rank-IC\": ric, \"mean-Rank-IC\": ric.mean()}\n            logger.info(\"--- Results for {:} ({:}) ---\".format(key, segment))\n            ic_x100, ric_x100 = ic * 100, ric * 100\n            logger.info(\"IC: {:.4f}%\".format(ic_x100.mean()))\n            logger.info(\"ICIR: {:.4f}%\".format(ic_x100.mean() / ic_x100.std()))","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/workflow/record_temp.py#L10-L46","documentation":"MultiSegRecord (qlib/contrib/workflow/record_temp.py) generates predictions per segment by calling model.predict(dataset, segment) and dataset.prepare(segments=..., ...), both of which are DatasetH APIs. The constructor therefore enforces isinstance(dataset, DatasetH) and raises ValueError naming the actual type otherwise.","triggerScenarios":"Passing anything other than a qlib.data.dataset.DatasetH instance to MultiSegRecord(model=..., dataset=...) — e.g. a plain DataFrame, a custom dataset class, or an DatasetH subclass imported from a different module path (isinstance still passes for real subclasses).","commonSituations":"Wiring record templates into a custom workflow whose dataset is a user-defined class; passing the handler instead of the dataset by mistake; newer qlib refactorings splitting DatasetH across modules.","solutions":["Build your dataset with DatasetH (qlib.data.dataset.DatasetH) before creating MultiSegRecord","If you use a custom dataset, either inherit from DatasetH or use a RecordTemp subclass that calls your own predict/prepare API","Make sure you pass the dataset object itself, not its handler or the underlying DataFrame"],"exampleFix":"# before\nfrom qlib.data.dataset.handler import DataHandlerLP\nrec = MultiSegRecord(model=model, dataset=my_handler)\n\n# after\nfrom qlib.data.dataset import DatasetH\ndataset = DatasetH(handler=my_handler, segments={\"train\": (...), \"test\": (...)})\nrec = MultiSegRecord(model=model, dataset=dataset)","handlingStrategy":"type-guard","validationCode":"from qlib.data.dataset import DatasetH\n\nassert isinstance(dataset, DatasetH), f'MultiSegRecord needs DatasetH, got {type(dataset).__name__}'\nrec = MultiSegRecord(model=model, dataset=dataset)","typeGuard":"from qlib.data.dataset import DatasetH\n\ndef is_dataset_h(obj) -> bool:\n    return isinstance(obj, DatasetH)","tryCatchPattern":null,"preventionTips":["Construct record templates with objects produced by qlib's own dataset factory (DatasetH), not raw handlers or DataFrames","Custom dataset classes should either subclass DatasetH or skip MultiSegRecord in favor of a custom RecordTemp"],"tags":["qlib","workflow","record","type-guard"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}