{"record":{"id":"f1367b03eb275e7a","repo":"microsoft/qlib","slug":"multiple-paths-are-found-with-prefix-filename-wi","errorCode":null,"errorMessage":"Multiple paths are found with prefix '{filename_without_suffix}': {paths}","messagePattern":"Multiple paths are found with prefix '(.+?)': (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/rl/data/pickle_styled.py","lineNumber":80,"sourceCode":"        ]\n    if shape == 6:\n        return [\"$high\", \"$low\", \"$open\", \"$close\", \"$vwap\", \"$volume\"]\n    elif shape == 5:\n        return [\"$high\", \"$low\", \"$open\", \"$close\", \"$volume\"]\n    raise ValueError(f\"Unrecognized data shape: {shape}\")\n\n\ndef _find_pickle(filename_without_suffix: Path) -> Path:\n    suffix_list = [\".pkl\", \".pkl.backtest\"]\n    paths: List[Path] = []\n    for suffix in suffix_list:\n        path = filename_without_suffix.parent / (filename_without_suffix.name + suffix)\n        if path.exists():\n            paths.append(path)\n    if not paths:\n        raise FileNotFoundError(f\"No file starting with '{filename_without_suffix}' found\")\n    if len(paths) > 1:\n        raise ValueError(f\"Multiple paths are found with prefix '{filename_without_suffix}': {paths}\")\n    return paths[0]\n\n\n@lru_cache(maxsize=10)  # 10 * 40M = 400MB\ndef _read_pickle(filename_without_suffix: Path) -> pd.DataFrame:\n    df = pd.read_pickle(_find_pickle(filename_without_suffix))\n    index_cols = df.index.names\n\n    df = df.reset_index()\n    for date_col_name in [\"date\", \"datetime\"]:\n        if date_col_name in df:\n            df[date_col_name] = pd.to_datetime(df[date_col_name])\n    df = df.set_index(index_cols)\n\n    return df\n\n\nclass SimpleIntradayBacktestData(BaseIntradayBacktestData):","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/rl/data/pickle_styled.py#L62-L98","documentation":"_find_pickle (qlib/rl/data/pickle_styled.py:80) probes both '<name>.pkl' and '<name>.pkl.backtest'. Because later code must pick exactly one file, finding both raises ValueError(\"Multiple paths are found with prefix '<name>': [paths]\"). This guards against silently backtesting against an ambiguous/stale data version.","triggerScenarios":"A directory containing both orders_<name>.pkl and orders_<name>.pkl.backtest (or process data equivalents) for the same base name; regenerating backtest artifacts without cleaning the previous .pkl.backtest file.","commonSituations":"Re-running backtest data generation scripts that leave old .pkl.backtest copies next to new .pkl dumps; switching between backtest and non-backtest data generation modes in one workspace.","solutions":["Delete or move one of the two files so only .pkl or only .pkl.backtest remains","Prefer keeping the fresh .pkl dump and removing the stale .pkl.backtest","Clean the data directory between regeneration runs"],"exampleFix":"# before\n# dir contains: orders.pkl  AND  orders.pkl.backtest -> ValueError\n\n# after (shell)\nrm data/orders.pkl.backtest   # keep the fresh dump\n# or in python\nfor extra in base.parent.glob(base.name + '.pkl.backtest'):\n    extra.unlink()","handlingStrategy":"validation","validationCode":"found = [p for p in (base.with_name(base.name + '.pkl'), base.with_name(base.name + '.pkl.backtest')) if p.is_file()]\nassert len(found) == 1, f'ambiguous pickle files: {found}'","typeGuard":null,"tryCatchPattern":"try:\n    df = _read_pickle(base)\nexcept ValueError as e:\n    if 'Multiple paths' in str(e):\n        base.with_name(base.name + '.pkl.backtest').unlink(missing_ok=True)  # keep .pkl\n        df = _read_pickle(base)\n    else:\n        raise","preventionTips":["Clean stale .pkl.backtest artifacts after regenerating dumps","Use separate output directories per data generation run"],"tags":["qlib","rl","pickle","ambiguous-files","value-error"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}