OpenBB-finance/OpenBB · error · RuntimeError

Column '{target_col}' not found in the data.

Error message

Column '{target_col}' not found in the data.

What it means

The BLS charting view pivots the data by (symbol, date) around a value column (default 'value', overridable via target_col). If target_col is not among the DataFrame columns, the pivot is impossible and RuntimeError('Column {target_col} not found in the data.') is raised. BLS models expose the observation as 'value', so a custom payload lacking it fails here.

Source

Thrown at openbb_platform/extensions/economy/openbb_economy/economy_views.py:384

            else kwargs.get("obbject_item")
        )
        df = DataFrame()

        if isinstance(_data, DataFrame) and not _data.empty:
            df = _data.reset_index() if _data.index.name == "date" else _data
        else:
            try:
                df = basemodel_to_df(_data, index=None)  # type: ignore
            except Exception as e:
                raise RuntimeError("Unable to process supplied data.") from e

        if df.empty or len(df) < 2:
            raise RuntimeError("No data found to plot.")

        cols = df.columns.to_list()
        target_col = kwargs.get("target_col", "value")
        if target_col not in cols:
            raise RuntimeError(f"Column '{target_col}' not found in the data.")

        new_df = df.pivot(columns="symbol", values=target_col, index="date")
        target_symbols = kwargs.get("target_symbol", "").split(",")[:10]  # type: ignore

        if not target_symbols or len(target_symbols) == 0 or target_symbols[0] == "":
            target_symbols = new_df.columns.to_list()[:10]

        metadata = kwargs["extra"].get("results_metadata", {})  # type: ignore
        ytitle = kwargs.get("ytitle", "")

        new_df = new_df.filter(target_symbols, axis=1)

        if "percent" in target_col.lower():  # type: ignore
            ytitle = (
                ytitle
                if ytitle
                else target_col.replace("change_percent_", "").replace("M", " Month") + " Change (%)"  # type: ignore
            )

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Omit target_col so the default 'value' is used with native BLS results.
  2. Rename your injected column: df = df.rename(columns={'rate': 'value'}) before passing data=df.
  3. Pass target_col matching an existing column: check df.columns first.

Example fix

# before
fig = views.bls_chart(data=df.rename(columns={'value':'obs'}), target_col='value')

# after
df = df.rename(columns={'obs': 'value'})
fig = views.bls_chart(data=df)  # default target_col='value' now resolves
Defensive patterns

Strategy: validation

Validate before calling

df = res.to_df() if hasattr(res, 'to_df') else data
target_col = kwargs.get('target_col', 'value')
assert target_col in df.columns, (
    f'{target_col!r} missing; available: {df.columns.tolist()}'
)

Type guard

def has_column(df, name: str) -> bool:
    """True when the DataFrame exposes the named column."""
    return name in getattr(df, 'columns', [])

Try / catch

try:
    fig = views.bls_chart(target_col=target_col, **kwargs)
except RuntimeError as e:
    if 'not found in the data' in str(e):
        fig = views.bls_chart(**{k: v for k, v in kwargs.items() if k != 'target_col'})
    else:
        raise

Prevention

When it happens

Trigger: Passing target_col='price' (or anything != a real column) in charting kwargs; injecting a DataFrame whose value field is named differently (e.g. 'rate', 'close'); using a provider model without a 'value' field.

Common situations: Reusing charting kwargs from another endpoint, custom DataFrames built from CSVs with different column names, or renaming columns during preprocessing.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/87549a5bd4a75f18. Report an issue: GitHub.