microsoft/qlib · error · NotImplementedError
This type of input is not supported
Error message
This type of input is not supported
What it means
_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.
Source
Thrown at qlib/contrib/data/dataset.py:218
# add memory (sample wise and daily)
if self.memory_mode == "sample":
self._memory = np.zeros((len(self._data), self.num_states), dtype=np.float32)
elif self.memory_mode == "daily":
self._memory = np.zeros((len(self._daily_index), self.num_states), dtype=np.float32)
else:
raise ValueError(f"invalid memory_mode `{self.memory_mode}`")
# padding tensor
self._zeros = np.zeros((self.seq_len, max(self.num_states, self._data.shape[1])), dtype=np.float32)
def _prepare_seg(self, slc, **kwargs):
fn = _get_date_parse_fn(self._index[0][1])
if isinstance(slc, slice):
start, stop = slc.start, slc.stop
elif isinstance(slc, (list, tuple)):
start, stop = slc
else:
raise NotImplementedError(f"This type of input is not supported")
start_date = pd.Timestamp(fn(start))
end_date = pd.Timestamp(fn(stop))
obj = copy.copy(self) # shallow copy
# NOTE: Seriable will disable copy `self._data` so we manually assign them here
obj._data = self._data # reference (no copy)
obj._label = self._label
obj._index = self._index
obj._memory = self._memory
obj._zeros = self._zeros
# update index for this batch
date_index = self._index.get_level_values(1)
obj._batch_slices = self._batch_slices[(date_index >= start_date) & (date_index <= end_date)]
mask = (self._daily_index.values >= start_date) & (self._daily_index.values <= end_date)
obj._daily_slices = self._daily_slices[mask]
obj._daily_index = self._daily_index[mask]
return obj
def restore_index(self, index):View on GitHub (pinned to 79633dd950)
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.
Example fix
# before seg = ds._prepare_seg(np.int64(100)) # -> NotImplementedError # after start, stop = ds._index[100][1], ds._index[-1][1] seg = ds._prepare_seg((start, stop)) # 2-element tuple of timestamps
Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(seg, (slice, list, tuple)), f'segment must be slice or 2-element list/tuple, got {type(seg).__name__}'
if isinstance(seg, (list, tuple)):
assert len(seg) == 2, 'segment container must have exactly two elements' Type guard
def is_valid_segment(s) -> bool:
return isinstance(s, slice) or (isinstance(s, (list, tuple)) and len(s) == 2) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- invalid memory_mode `{self.memory_mode}`
- cannot assign data as `num_states==0`
- cannot clear memory as `num_states==0`
- This type of signal is not supported
- Must specify the path to save the dataset.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/1bb08c066319ac19.
Report an issue: GitHub.