{"record":{"id":"bf9719e3a5a5fe13","repo":"microsoft/qlib","slug":"unsupported-input-type-for-param-instrument","errorCode":null,"errorMessage":"Unsupported input type for param `instrument`","messagePattern":"Unsupported input type for param `instrument`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/data/data.py","lineNumber":528,"sourceCode":"    @staticmethod\n    def get_instruments_d(instruments, freq):\n        \"\"\"\n        Parse different types of input instruments to output instruments_d\n        Wrong format of input instruments will lead to exception.\n\n        \"\"\"\n        if isinstance(instruments, dict):\n            if \"market\" in instruments:\n                # dict of stockpool config\n                instruments_d = Inst.list_instruments(instruments=instruments, freq=freq, as_list=False)\n            else:\n                # dict of instruments and timestamp\n                instruments_d = instruments\n        elif isinstance(instruments, (list, tuple, pd.Index, np.ndarray)):\n            # list or tuple of a group of instruments\n            instruments_d = list(instruments)\n        else:\n            raise ValueError(\"Unsupported input type for param `instrument`\")\n        return instruments_d\n\n    @staticmethod\n    def get_column_names(fields):\n        \"\"\"\n        Get column names from input fields\n\n        \"\"\"\n        if len(fields) == 0:\n            raise ValueError(\"fields cannot be empty\")\n        column_names = [str(f) for f in fields]\n        return column_names\n\n    @staticmethod\n    def parse_fields(fields):\n        # parse and check the input fields\n        return [ExpressionD.get_expression_instance(f) for f in fields]\n","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/data/data.py#L510-L546","documentation":"`Cal.calendar`-side sibling check in `Inst.get_instruments_d`: the `instruments` parameter of dataset/D.features calls must be either a dict (stockpool config if it has key 'market', else an {instrument: (start,end)} dict) or a list/tuple/pd.Index/np.ndarray. Any other type raises this ValueError before data loading starts.","triggerScenarios":"Calling `D.features(instruments='csi300', ...)` or `DatasetH(instruments='all', ...)` with a bare string/None/int. Same shape rules as get_inst_type but a different error site.","commonSituations":"Passing market names as plain strings into DatasetH/D.features; passing a set of instruments (not accepted); passing None after a config-processing bug.","solutions":["Wrap the string: `D.features(instruments={'market': 'csi300'}, ...)` or `instruments=D.instruments('csi300')`.","Convert sets: `instruments=list(my_set)`.","For per-instrument time ranges, use `{'SH600000': ('2015-01-01', '2020-12-31')}`."],"exampleFix":"# before\ndf = D.features('csi300', ['$close'], start_time='2020-01-01', end_time='2020-12-31')\n\n# after\ndf = D.features({'market': 'csi300'}, ['$close'], start_time='2020-01-01', end_time='2020-12-31')","handlingStrategy":"type-guard","validationCode":"import pandas as pd, numpy as np\n\ndef normalize_instruments(inst):\n    if isinstance(inst, str):\n        return {'market': inst}          # 'csi300' -> market config\n    if isinstance(inst, set):\n        return list(inst)\n    assert isinstance(inst, (dict, list, tuple, pd.Index, np.ndarray)), 'bad instruments type'\n    return inst","typeGuard":"import pandas as pd, np\n\ndef is_supported_instruments(inst) -> bool:\n    return isinstance(inst, (dict, list, tuple, pd.Index, np.ndarray))","tryCatchPattern":null,"preventionTips":["Normalize instruments through D.instruments()/list() at the config boundary.","Never pass bare market strings or sets downstream."],"tags":["instruments","api-usage","validation"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}