{"record":{"id":"166752326e777e0c","repo":"microsoft/qlib","slug":"this-type-of-input-is-not-supported-166752","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/data/dataset/utils.py","lineNumber":38,"sourceCode":"        data\n    level : Union[str, int]\n        index level\n\n    Returns\n    -------\n    int:\n        The level index in the multiple index\n    \"\"\"\n    if isinstance(level, str):\n        try:\n            return df.index.names.index(level)\n        except (AttributeError, ValueError):\n            # NOTE: If level index is not given in the data, the default level index will be ('datetime', 'instrument')\n            return (\"datetime\", \"instrument\").index(level)\n    elif isinstance(level, int):\n        return level\n    else:\n        raise NotImplementedError(f\"This type of input is not supported\")\n\n\ndef fetch_df_by_index(\n    df: pd.DataFrame,\n    selector: Union[pd.Timestamp, slice, str, list, pd.Index],\n    level: Union[str, int],\n    fetch_orig=True,\n) -> pd.DataFrame:\n    \"\"\"\n    fetch data from `data` with `selector` and `level`\n\n    selector are assumed to be well processed.\n    `fetch_df_by_index` is only responsible for get the right level\n\n    Parameters\n    ----------\n    selector : Union[pd.Timestamp, slice, str, list]\n        selector","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/data/dataset/utils.py#L20-L56","documentation":"Raised by get_level_index (qlib/data/dataset/utils.py) when its level argument is neither a str nor an int. The function resolves a level name to its integer position in a DataFrame's MultiIndex (falling back to the conventional ('datetime','instrument') names); only strings and integers are meaningful inputs, so anything else raises NotImplementedError.","triggerScenarios":"get_level_index(df, level=None), level=1.0 (float), level=slice(None), or a variable holding an unexpected object. Often hit indirectly through fetch_df_by_index or dataset code that forwards an unvalidated level value.","commonSituations":"A level parameter defaults to None in caller code and is passed through without setting it; passing a numpy integer (np.int64) usually works because isinstance(np.int64(...), int) can be False on some platforms/versions — if so, cast to plain int; refactoring code and losing the level argument.","solutions":["Pass the level as a plain str (e.g. \"datetime\" or \"instrument\") or a plain int (e.g. 0 or 1).","Ensure the level variable is not None: give it an explicit default in your calling code.","If the value may be a numpy integer, coerce with int(level) before calling."],"exampleFix":"# before\nlevel = None  # fell through from caller\nidx = get_level_index(df, level)\n\n# after\nidx = get_level_index(df, level=\"datetime\")  # or level=0","handlingStrategy":"validation","validationCode":"if not isinstance(level, (str, int)) or level is None:\n    raise TypeError(\"level must be str or int\")","typeGuard":"def is_valid_level(lv) -> bool:\n    return isinstance(lv, (str, int)) and not isinstance(lv, bool) and lv is not None","tryCatchPattern":null,"preventionTips":["Always pass an explicit level (\"datetime\", \"instrument\", 0, 1).","Coerce numpy integers with int() before passing through."],"tags":["qlib","dataframe","multiindex","type-error"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}