{"record":{"id":"fd88cffd45ecffd6","repo":"microsoft/qlib","slug":"unsupported-order-file-type-order-file","errorCode":null,"errorMessage":"Unsupported order file type: {order_file}","messagePattern":"Unsupported order file type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"qlib/rl/contrib/utils.py","lineNumber":22,"sourceCode":"from __future__ import annotations\n\nfrom pathlib import Path\n\nimport pandas as pd\n\n\ndef read_order_file(order_file: Path | pd.DataFrame) -> pd.DataFrame:\n    if isinstance(order_file, pd.DataFrame):\n        return order_file\n\n    order_file = Path(order_file)\n\n    if order_file.suffix == \".pkl\":\n        order_df = pd.read_pickle(order_file).reset_index()\n    elif order_file.suffix == \".csv\":\n        order_df = pd.read_csv(order_file)\n    else:\n        raise TypeError(f\"Unsupported order file type: {order_file}\")\n\n    if \"date\" in order_df.columns:\n        # legacy dataframe columns\n        order_df = order_df.rename(columns={\"date\": \"datetime\", \"order_type\": \"direction\"})\n    order_df[\"datetime\"] = order_df[\"datetime\"].astype(str)\n\n    return order_df\n","sourceCodeStart":4,"sourceCodeEnd":30,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/rl/contrib/utils.py#L4-L30","documentation":"read_order_file (qlib/rl/contrib/utils.py:22) loads an order list for RL backtests. It accepts an already-built pd.DataFrame directly, or a path whose suffix is .pkl (read via pd.read_pickle + reset_index) or .csv (read via pd.read_csv). Any other suffix (.parquet, .txt, .json, no suffix) raises TypeError('Unsupported order file type: <path>').","triggerScenarios":"Calling read_order_file('orders.parquet'), read_order_file('orders.json'), or passing a Path with an unexpected/empty suffix; also triggered by files whose name merely contains '.csv' not at the end.","commonSituations":"Users exporting orders from their own systems as parquet/json; renaming exported order files; passing a directory-like Path with no suffix.","solutions":["Save orders as .csv or .pkl and pass that path","Load the data yourself and pass the pd.DataFrame directly, which bypasses the suffix check","Convert parquet/json orders to CSV: df.to_csv('orders.csv', index=False)"],"exampleFix":"# before\norder_df = read_order_file('orders.parquet')  # TypeError\n\n# after\norder_df = read_order_file(pd.read_parquet('orders.parquet'))\n# or convert once:\n# pd.read_parquet('orders.parquet').to_csv('orders.csv', index=False)","handlingStrategy":"type-guard","validationCode":"from pathlib import Path\nif not isinstance(order_file, pd.DataFrame):\n    assert Path(order_file).suffix in ('.pkl', '.csv'), f'order file must be .pkl/.csv or DataFrame: {order_file}'","typeGuard":"def is_supported_order_source(src) -> bool:\n    return isinstance(src, pd.DataFrame) or Path(src).suffix in ('.pkl', '.csv')","tryCatchPattern":"try:\n    df = read_order_file(order_file)\nexcept TypeError as e:\n    df = read_order_file(pd.read_parquet(order_file))  # manual load fallback","preventionTips":["Export order lists as CSV or pickle","Pass DataFrames directly in programmatic pipelines"],"tags":["qlib","rl","orders","file-format","type-error"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}