microsoft/qlib · error · NotImplementedError

This type of input is not supported

Error message

This type of input is not supported

What it means

TSDataSampler.__get_idx accepts exactly two index shapes: an int (flat sample number) or a (date, instrument) tuple for coordinate lookup. Anything else — a string alone, a list of strings, None — raises NotImplementedError.

Source

Thrown at qlib/data/dataset/__init__.py:594

        Tuple[int]:
            the row and col index
        """
        # The the right row number `i` and col number `j` in idx_df
        if isinstance(idx, (int, np.integer)):
            real_idx = idx
            if 0 <= real_idx < len(self.idx_map):
                i, j = self.idx_map[real_idx]  # TODO: The performance of this line is not good
            else:
                raise KeyError(f"{real_idx} is out of [0, {len(self.idx_map)})")
        elif isinstance(idx, tuple):
            # <TSDataSampler object>["datetime", "instruments"]
            date, inst = idx
            date = pd.Timestamp(date)
            i = bisect.bisect_right(self.idx_df.index, date) - 1
            # NOTE: This relies on the idx_df columns sorted in `__init__`
            j = bisect.bisect_left(self.idx_df.columns, inst)
        else:
            raise NotImplementedError(f"This type of input is not supported")
        return i, j

    def __getitem__(self, idx: Union[int, Tuple[object, str], List[int]]):
        """
        # We have two method to get the time-series of a sample
        tsds is a instance of TSDataSampler

        # 1) sample by int index directly
        tsds[len(tsds) - 1]

        # 2) sample by <datetime,instrument> index
        tsds['2016-12-31', "SZ300315"]

        # The return value will be similar to the data retrieved by following code
        df.loc(axis=0)['2015-01-01':'2016-12-31', "SZ300315"].iloc[-30:]

        Parameters
        ----------

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use a tuple: `tsds['2016-12-31', 'SZ300315']`.
  2. Or use an integer index: `tsds[len(tsds) - 1]`.
  3. Convert lists to tuples: `tsds[tuple(key)]`.

Example fix

# before
sample = tsds['SH600000']

# after
sample = tsds['2020-01-01', 'SH600000']  # (date, instrument) tuple
Defensive patterns

Strategy: type-guard

Validate before calling

def valid_tsds_key(idx) -> bool:
    return isinstance(idx, int) or (isinstance(idx, tuple) and len(idx) == 2)

Type guard

from typing import Union, Tuple, object as _o

def is_tsds_key(idx) -> bool:
    return isinstance(idx, int) or (isinstance(idx, tuple) and len(idx) == 2)

Prevention

When it happens

Trigger: Calling `tsds['SH600000']` (instrument alone) or `tsds[['2020-01-01','SH600000']]` (list instead of tuple), or `tsds['2020-01-01', 'SH600000', 'extra']`.

Common situations: Code migrating from pandas DataFrame indexing where single-key access works; json-decoded keys that arrive as lists rather than tuples.

Related errors


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