{"record":{"id":"e7151c8a39630a08","repo":"microsoft/qlib","slug":"axis-must-be-0-or-1","errorCode":null,"errorMessage":"axis must be 0 or 1","messagePattern":"axis must be 0 or 1","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/utils/index_data.py","lineNumber":54,"sourceCode":"        raise NotImplementedError(f\"please implement this func when axis == 0\")\n    elif axis == 1:\n        # get all index and row\n        all_index = set()\n        for index_data in data_list:\n            all_index = all_index | set(index_data.index)\n        all_index = list(all_index)\n        all_index.sort()\n        all_index_map = dict(zip(all_index, range(len(all_index))))\n\n        # concat all\n        tmp_data = np.full((len(all_index), len(data_list)), np.nan)\n        for data_id, index_data in enumerate(data_list):\n            assert isinstance(index_data, SingleData)\n            now_data_map = [all_index_map[index] for index in index_data.index]\n            tmp_data[now_data_map, data_id] = index_data.data\n        return MultiData(tmp_data, all_index)\n    else:\n        raise ValueError(f\"axis must be 0 or 1\")\n\n\ndef sum_by_index(data_list: Union[SingleData], new_index: list, fill_value=0) -> SingleData:\n    \"\"\"concat all SingleData by new index.\n\n    Parameters\n    ----------\n    data_list : List[SingleData]\n        the list of all SingleData to sum.\n    new_index : list\n        the new_index of new SingleData.\n    fill_value : float\n        fill the missing values or replace np.nan.\n\n    Returns\n    -------\n    SingleData\n        the SingleData with new_index and values after sum.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/utils/index_data.py#L36-L72","documentation":"Raised by the concat helper in qlib/utils/index_data.py when merging SingleData/MultiData objects along an axis other than 0 or 1. The underlying storage is a plain numpy matrix, so only stacking by rows (axis=0) or by columns (axis=1) is meaningful. Any other axis value has no equivalent operation on this data structure.","triggerScenarios":"Calling concat(data_list, axis=2), axis=-1, or passing a non-integer axis (e.g. a string like 'columns') to qlib.utils.index_data.concat with a list of SingleData objects.","commonSituations":"Porting pandas concat/df.stack code that uses axis names or higher axes; refactoring expression or data-handler pipelines that assumed DataFrame semantics; copy-pasting an axis value from a numpy call that allowed axis=2 on 3-D arrays.","solutions":["Use axis=0 to stack data on new rows (result keeps column index) or axis=1 to add new columns (result keeps row index).","If you need a higher-dimensional merge, do it in two steps: concat with axis=1 first, then wrap or transform the resulting MultiData manually.","Convert to pandas (data.to_dataframe() or pd.DataFrame(multi_data.data, index=..., columns=...)) if your operation genuinely requires axes beyond 2."],"exampleFix":"// before\nmerged = concat(single_data_list, axis=2)  # ValueError\n\n// after\nmerged = concat(single_data_list, axis=1)  # add each SingleData as a new column","handlingStrategy":"validation","validationCode":"from qlib.utils.index_data import concat\nassert axis in (0, 1), f\"concat supports axis 0/1 only, got {axis}\"\nmerged = concat(data_list, axis=axis)","typeGuard":"def is_valid_concat_axis(axis) -> bool:\n    return axis in (0, 1)","tryCatchPattern":null,"preventionTips":["Treat qlib's index-data containers as strictly 2-D; never forward unchecked axis values from user config into concat.","Map pandas-style axis names to 0/1 ('index'->0, 'columns'->1) at your API boundary."],"tags":["qlib","index-data","concat","axis","valueerror"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}