{"record":{"id":"36a563fe3d74c743","repo":"HKUDS/Vibe-Trading","slug":"exposures-must-be-a-non-empty-dataframe","errorCode":null,"errorMessage":"exposures must be a non-empty DataFrame","messagePattern":"exposures must be a non-empty DataFrame","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/factormodel.py","lineNumber":639,"sourceCode":"            Defaults to zero if omitted.\n\n    Returns:\n        :class:`FactorRiskDecomposition` containing total/factor/specific\n        variances, volatilities, marginal contributions to risk (MCR), and\n        percentage contributions to risk (PCR) per factor and per asset.\n\n    Raises:\n        ValueError: If weights or matrices are empty, contain non-finite values,\n            or share no common assets or factors.\n    \"\"\"\n    w_series = pd.Series(portfolio_weights, dtype=float)\n    if w_series.empty:\n        raise ValueError(\"portfolio_weights cannot be empty\")\n    if not np.isfinite(w_series.values).all():\n        raise ValueError(\"portfolio_weights contains non-finite values\")\n\n    if not isinstance(exposures, pd.DataFrame) or exposures.empty:\n        raise ValueError(\"exposures must be a non-empty DataFrame\")\n    if not np.isfinite(exposures.values).all():\n        raise ValueError(\"exposures contains non-finite values\")\n\n    if not isinstance(factor_cov, pd.DataFrame) or factor_cov.empty:\n        raise ValueError(\"factor_cov must be a non-empty DataFrame\")\n    if not np.isfinite(factor_cov.values).all():\n        raise ValueError(\"factor_cov contains non-finite values\")\n\n    # Align assets\n    assets = w_series.index.intersection(exposures.index)\n    if assets.empty:\n        raise ValueError(\n            f\"No matching assets between weights ({sorted(w_series.index)}) and exposures ({sorted(exposures.index)})\"\n        )\n\n    unmatched_weight = float(w_series.drop(index=assets, errors=\"ignore\").abs().sum())\n    w = w_series.loc[assets]\n    X = exposures.loc[assets]","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/factormodel.py#L621-L657","documentation":"The exposures argument must be a non-empty pandas DataFrame (assets x factors). Passing something else — a Series, ndarray, dict, or empty frame — trips this guard before any math runs.","triggerScenarios":"exposures=pd.Series(...), np.array(...), {}, or pd.DataFrame() passed as the second argument.","commonSituations":"Refactor changed the exposure loader to return a Series; a mock/stub returned a dict; empty frame after slicing all rows away.","solutions":["Pass exposures.loc[assets, factors] as a real 2-D DataFrame","Fix the upstream loader to return a DataFrame","Construct explicitly: pd.DataFrame(data, index=assets, columns=factors)"],"exampleFix":"# before\nrisk = factor_risk_decomposition(w, exposures_dict, F)\n# after\nX = pd.DataFrame(exposures_dict).T  # or load as DataFrame\nrisk = factor_risk_decomposition(w, X, F)","handlingStrategy":"type-guard","validationCode":"assert isinstance(exposures, pd.DataFrame) and not exposures.empty","typeGuard":"def is_exposure_frame(x) -> bool:\n    return isinstance(x, pd.DataFrame) and not x.empty and x.shape[1] > 0","tryCatchPattern":null,"preventionTips":["Pin loader return types to DataFrame in type hints","Add unit tests asserting the loader's output type"],"tags":["quantlib","factormodel","type-validation","dataframe"],"backgroundTag":"wrong-argument-type","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}