{"record":{"id":"1bb08c066319ac19","repo":"microsoft/qlib","slug":"this-type-of-input-is-not-supported-1bb08c","errorCode":null,"errorMessage":"This type of input is not supported","messagePattern":"This type of input is not supported","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/data/dataset.py","lineNumber":218,"sourceCode":"        # add memory (sample wise and daily)\n        if self.memory_mode == \"sample\":\n            self._memory = np.zeros((len(self._data), self.num_states), dtype=np.float32)\n        elif self.memory_mode == \"daily\":\n            self._memory = np.zeros((len(self._daily_index), self.num_states), dtype=np.float32)\n        else:\n            raise ValueError(f\"invalid memory_mode `{self.memory_mode}`\")\n\n        # padding tensor\n        self._zeros = np.zeros((self.seq_len, max(self.num_states, self._data.shape[1])), dtype=np.float32)\n\n    def _prepare_seg(self, slc, **kwargs):\n        fn = _get_date_parse_fn(self._index[0][1])\n        if isinstance(slc, slice):\n            start, stop = slc.start, slc.stop\n        elif isinstance(slc, (list, tuple)):\n            start, stop = slc\n        else:\n            raise NotImplementedError(f\"This type of input is not supported\")\n        start_date = pd.Timestamp(fn(start))\n        end_date = pd.Timestamp(fn(stop))\n        obj = copy.copy(self)  # shallow copy\n        # NOTE: Seriable will disable copy `self._data` so we manually assign them here\n        obj._data = self._data  # reference (no copy)\n        obj._label = self._label\n        obj._index = self._index\n        obj._memory = self._memory\n        obj._zeros = self._zeros\n        # update index for this batch\n        date_index = self._index.get_level_values(1)\n        obj._batch_slices = self._batch_slices[(date_index >= start_date) & (date_index <= end_date)]\n        mask = (self._daily_index.values >= start_date) & (self._daily_index.values <= end_date)\n        obj._daily_slices = self._daily_slices[mask]\n        obj._daily_index = self._daily_index[mask]\n        return obj\n\n    def restore_index(self, index):","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/data/dataset.py#L200-L236","documentation":"_prepare_seg in qlib/contrib/data/dataset.py converts a segment specifier into (start_date, end_date). It only understands a python slice, a 2-element list, or a 2-element tuple. Passing an int index, a numpy integer, a string segment name like 'train' (which top-level DatasetHK-style APIs use), or None raises NotImplementedError.","triggerScenarios":"Calling dataset.prepare(segment) / _prepare_seg with a bare int or np.int64 (e.g. an index computed from enumerate), a single timestamp, or a named segment string that this RL dataset does not support.","commonSituations":"Mixing qlib's Dataset/DatasetH API conventions ('train'/'valid' segment names) with this RL dataset that expects explicit ranges; slicing with numpy scalar types produced by argmax/searchsorted.","solutions":["Pass an explicit range: dataset.prepare(slice(start, stop)) or dataset.prepare((start, stop)) with values convertible by _get_date_parse_fn.","Convert numpy scalars to python ints/strings before passing.","Do not pass segment-name strings; resolve them to concrete timestamps first if you reuse generic qlib workflow code."],"exampleFix":"# before\nseg = ds._prepare_seg(np.int64(100))  # -> NotImplementedError\n# after\nstart, stop = ds._index[100][1], ds._index[-1][1]\nseg = ds._prepare_seg((start, stop))  # 2-element tuple of timestamps","handlingStrategy":"type-guard","validationCode":"assert isinstance(seg, (slice, list, tuple)), f'segment must be slice or 2-element list/tuple, got {type(seg).__name__}'\nif isinstance(seg, (list, tuple)):\n    assert len(seg) == 2, 'segment container must have exactly two elements'","typeGuard":"def is_valid_segment(s) -> bool:\n    return isinstance(s, slice) or (isinstance(s, (list, tuple)) and len(s) == 2)","tryCatchPattern":null,"preventionTips":["Always pass explicit (start, stop) ranges or slices to this RL dataset's prepare/_prepare_seg.","Convert numpy scalar indices to concrete (start_date, stop_date) tuples derived from ds._index."],"tags":["qlib","dataset","type-guard","reinforcement-learning"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}