OpenBB-finance/OpenBB · error · OpenBBError
No 'weight' column found in the data.
Error message
No 'weight' column found in the data.
What it means
The ETF holdings chart (etf_views.py) builds a horizontal bar chart of top holdings weighted by a 'weight' column. After converting data/obbject_item to a DataFrame, it requires 'weight' to be present; without it there is no measure to rank holdings by, so OpenBBError('No \'weight\' column found in the data.') is raised.
Source
Thrown at openbb_platform/extensions/etf/openbb_etf/etf_views.py:57
def etf_holdings(
**kwargs,
) -> tuple[Union["OpenBBFigure", "Figure"], dict[str, Any]]:
"""Equity Compare Groups Chart."""
# pylint: disable=import-outside-toplevel
from pandas import DataFrame # noqa
from openbb_core.app.utils import basemodel_to_df # noqa
from openbb_core.app.model.abstract.error import OpenBBError # noqa
from openbb_charting.charts.generic_charts import bar_chart # noqa
if "data" in kwargs and isinstance(kwargs["data"], DataFrame):
data = kwargs["data"]
elif "data" in kwargs and isinstance(kwargs["data"], list):
data = basemodel_to_df(kwargs["data"], index=None) # type: ignore
else:
data = basemodel_to_df(kwargs["obbject_item"], index=None) # type: ignore
if "weight" not in data.columns:
raise OpenBBError("No 'weight' column found in the data.")
orientation = kwargs.get("orientation", "h")
limit = kwargs.get("limit", 20)
symbol = kwargs["standard_params"].get("symbol") # type: ignore
title = kwargs.get("title", f"Top {limit} {symbol} Holdings")
layout_kwargs = kwargs.get("layout_kwargs", {})
data = data.sort_values("weight", ascending=False)
limit = min(limit, len(data)) # type: ignore
target = data.head(limit)[["symbol", "weight"]].set_index("symbol")
target = target.multiply(100)
axis_title = "Weight (%)"
fig = bar_chart(
target.reset_index(),
"symbol",
["weight"],
title=title, # type: ignoreView on GitHub (pinned to 3e071fcc2c)
Solutions
- Use a provider whose ETF holdings include weights (check res.to_df().columns for 'weight').
- Rename before injecting: df = df.rename(columns={'allocation': 'weight'}).
- Verify the dataset is holdings data (has 'symbol') and not another ETF dataset.
Example fix
# before
fig = views.etf_holdings(data=df) # df has 'pct_of_assets', no 'weight'
# after
df = df.rename(columns={'pct_of_assets': 'weight'})
fig = views.etf_holdings(data=df) Defensive patterns
Strategy: validation
Validate before calling
df = res.to_df() if hasattr(res, 'to_df') else data
assert 'weight' in df.columns, (
f"holdings chart needs a 'weight' column; got {df.columns.tolist()}"
) Type guard
def has_weight_column(df) -> bool:
"""True when the holdings frame carries a 'weight' column."""
return 'weight' in getattr(df, 'columns', []) Try / catch
from openbb_core.app.model.abstract.error import OpenBBError
try:
fig = views.etf_holdings(**kwargs)
except OpenBBError as e:
if "No 'weight' column" in str(e):
df = df.rename(columns={'allocation': 'weight'})
fig = views.etf_holdings(data=df)
else:
raise Prevention
- Confirm 'weight' exists in res.to_df().columns before charting holdings.
- Standardize injected holdings frames to symbol/weight naming.
- Choose providers that publish holding weights.
When it happens
Trigger: Calling obb.etf.holdings(...).charting.to_chart() with a provider whose holdings model lacks a weight field; injecting a custom holdings DataFrame whose weighting column is named differently (e.g. 'weight_percent', 'allocation').
Common situations: Provider schema differences across ETF holdings sources, renaming columns during preprocessing, or charting holdings from a provider that returns only symbol/description.
Related errors
- Column '{target_col}' not found in the data.
- Error: Maturity column not found in the data.
- Column '{target}', or 'close', not found in the data.
- No holdings were found for {query.symbol}, and the response
- {data.get('message')} {query.symbol}: {data['error']}
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/926e832dbd705474.
Report an issue: GitHub.