microsoft/qlib · error · TypeError

Unsupported order file type

Error message

Unsupported order file type: {order_file}

What it means

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>').

Solutions

  1. Save orders as .csv or .pkl and pass that path
  2. Load the data yourself and pass the pd.DataFrame directly, which bypasses the suffix check
  3. Convert parquet/json orders to CSV: df.to_csv('orders.csv', index=False)

Example fix

# before
order_df = read_order_file('orders.parquet')  # TypeError

# after
order_df = read_order_file(pd.read_parquet('orders.parquet'))
# or convert once:
# pd.read_parquet('orders.parquet').to_csv('orders.csv', index=False)
Defensive patterns

Strategy: type-guard

Validate before calling

from pathlib import Path
if not isinstance(order_file, pd.DataFrame):
    assert Path(order_file).suffix in ('.pkl', '.csv'), f'order file must be .pkl/.csv or DataFrame: {order_file}'

Type guard

def is_supported_order_source(src) -> bool:
    return isinstance(src, pd.DataFrame) or Path(src).suffix in ('.pkl', '.csv')

Try / catch

try:
    df = read_order_file(order_file)
except TypeError as e:
    df = read_order_file(pd.read_parquet(order_file))  # manual load fallback

Prevention

When it happens

Trigger: 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.

Common situations: Users exporting orders from their own systems as parquet/json; renaming exported order files; passing a directory-like Path with no suffix.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/fd88cffd45ecffd6. Report an issue: GitHub.

Appendix: source

Thrown at qlib/rl/contrib/utils.py:22

from __future__ import annotations

from pathlib import Path

import pandas as pd


def read_order_file(order_file: Path | pd.DataFrame) -> pd.DataFrame:
    if isinstance(order_file, pd.DataFrame):
        return order_file

    order_file = Path(order_file)

    if order_file.suffix == ".pkl":
        order_df = pd.read_pickle(order_file).reset_index()
    elif order_file.suffix == ".csv":
        order_df = pd.read_csv(order_file)
    else:
        raise TypeError(f"Unsupported order file type: {order_file}")

    if "date" in order_df.columns:
        # legacy dataframe columns
        order_df = order_df.rename(columns={"date": "datetime", "order_type": "direction"})
    order_df["datetime"] = order_df["datetime"].astype(str)

    return order_df

View on GitHub (pinned to 79633dd950)