{"record":{"id":"926e832dbd705474","repo":"OpenBB-finance/OpenBB","slug":"no-weight-column-found-in-the-data","errorCode":null,"errorMessage":"No 'weight' column found in the data.","messagePattern":"No 'weight' column found in the data\\.","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/etf/openbb_etf/etf_views.py","lineNumber":57,"sourceCode":"    def etf_holdings(\n        **kwargs,\n    ) -> tuple[Union[\"OpenBBFigure\", \"Figure\"], dict[str, Any]]:\n        \"\"\"Equity Compare Groups Chart.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        from pandas import DataFrame  # noqa\n        from openbb_core.app.utils import basemodel_to_df  # noqa\n        from openbb_core.app.model.abstract.error import OpenBBError  # noqa\n        from openbb_charting.charts.generic_charts import bar_chart  # noqa\n\n        if \"data\" in kwargs and isinstance(kwargs[\"data\"], DataFrame):\n            data = kwargs[\"data\"]\n        elif \"data\" in kwargs and isinstance(kwargs[\"data\"], list):\n            data = basemodel_to_df(kwargs[\"data\"], index=None)  # type: ignore\n        else:\n            data = basemodel_to_df(kwargs[\"obbject_item\"], index=None)  # type: ignore\n\n        if \"weight\" not in data.columns:\n            raise OpenBBError(\"No 'weight' column found in the data.\")\n\n        orientation = kwargs.get(\"orientation\", \"h\")\n        limit = kwargs.get(\"limit\", 20)\n        symbol = kwargs[\"standard_params\"].get(\"symbol\")  # type: ignore\n        title = kwargs.get(\"title\", f\"Top {limit} {symbol} Holdings\")\n        layout_kwargs = kwargs.get(\"layout_kwargs\", {})\n\n        data = data.sort_values(\"weight\", ascending=False)\n        limit = min(limit, len(data))  # type: ignore\n        target = data.head(limit)[[\"symbol\", \"weight\"]].set_index(\"symbol\")\n        target = target.multiply(100)\n        axis_title = \"Weight (%)\"\n\n        fig = bar_chart(\n            target.reset_index(),\n            \"symbol\",\n            [\"weight\"],\n            title=title,  # type: ignore","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/etf/openbb_etf/etf_views.py#L39-L75","documentation":"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.","triggerScenarios":"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').","commonSituations":"Provider schema differences across ETF holdings sources, renaming columns during preprocessing, or charting holdings from a provider that returns only symbol/description.","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."],"exampleFix":"# before\nfig = views.etf_holdings(data=df)  # df has 'pct_of_assets', no 'weight'\n\n# after\ndf = df.rename(columns={'pct_of_assets': 'weight'})\nfig = views.etf_holdings(data=df)","handlingStrategy":"validation","validationCode":"df = res.to_df() if hasattr(res, 'to_df') else data\nassert 'weight' in df.columns, (\n    f\"holdings chart needs a 'weight' column; got {df.columns.tolist()}\"\n)","typeGuard":"def has_weight_column(df) -> bool:\n    \"\"\"True when the holdings frame carries a 'weight' column.\"\"\"\n    return 'weight' in getattr(df, 'columns', [])","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\ntry:\n    fig = views.etf_holdings(**kwargs)\nexcept OpenBBError as e:\n    if \"No 'weight' column\" in str(e):\n        df = df.rename(columns={'allocation': 'weight'})\n        fig = views.etf_holdings(data=df)\n    else:\n        raise","preventionTips":["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."],"tags":["etf","charting","column-missing","holdings"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}