{"record":{"id":"a9c6c030cb5ac580","repo":"HKUDS/Vibe-Trading","slug":"alpha-id-output-shape-result-shape-close-s","errorCode":null,"errorMessage":"{alpha_id}: output shape {result.shape} != close shape {ref.shape}","messagePattern":"(.+?): output shape (.+?) != close shape (.+?)","errorType":"validation","errorClass":"RegistryError","httpStatus":null,"severity":"error","filePath":"agent/src/factors/registry.py","lineNumber":388,"sourceCode":"            spec.loader.exec_module(module)\n        except Exception:\n            sys.modules.pop(alpha.module_path, None)\n            raise\n        return module\n\n    @staticmethod\n    def _validate_output(\n        alpha_id: str,\n        result: Any,\n        panel: dict[str, pd.DataFrame],\n    ) -> pd.DataFrame:\n        if not isinstance(result, pd.DataFrame):\n            raise RegistryError(\n                f\"{alpha_id}: compute() returned {type(result).__name__}, expected DataFrame\"\n            )\n        ref = panel.get(\"close\")\n        if ref is not None and result.shape != ref.shape:\n            raise RegistryError(\n                f\"{alpha_id}: output shape {result.shape} != close shape {ref.shape}\"\n            )\n        arr = result.to_numpy(dtype=np.float64, na_value=np.nan)\n        if np.isinf(arr).any():\n            raise RegistryError(f\"{alpha_id}: output contains +/- inf\")\n        nan_ratio = float(np.isnan(arr).mean()) if arr.size > 0 else 1.0\n        if nan_ratio > 0.95:\n            raise RegistryError(f\"{alpha_id}: output >95% NaN (nan_ratio={nan_ratio:.3f})\")\n        return result\n\n    def export_manifest(self) -> dict[str, Any]:\n        \"\"\"Return a JSON-serialisable snapshot for wiki rendering.\"\"\"\n        from datetime import datetime, timezone\n\n        zoos: dict[str, list[dict[str, Any]]] = {}\n        for a in self._alphas.values():\n            zoos.setdefault(a.zoo, []).append(\n                {","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/factors/registry.py#L370-L406","documentation":"_validate_output compares the result's shape to the panel's 'close' DataFrame; every factor must produce a matrix with identical (rows, cols) so outputs stack across alphas. Mismatched shapes are rejected.","triggerScenarios":"compute returns a subset of columns, a resampled/reindexed frame, or drops NaN rows — anything changing shape relative to panel['close'].","commonSituations":"Factor drops symbols with missing data (dropna), computes only on filtered tickers, or reindexes dates; panels with duplicated symbols causing shape drift.","solutions":["Reindex the result to close's index and columns before returning: `result = result.reindex(index=close.index, columns=close.columns)`","Avoid dropna on axes; use fillna/leave NaNs (up to 95% allowed)","Compute on full-dimension intermediates"],"exampleFix":"# before\nreturn df.dropna(axis=1, how='all')\n# after\nreturn df.reindex(index=close.index, columns=close.columns)","handlingStrategy":"validation","validationCode":"ref = panel['close']\nassert result.shape == ref.shape, (result.shape, ref.shape)","typeGuard":null,"tryCatchPattern":"try:\n    out = registry.compute(aid, panel)\nexcept RegistryError as e:\n    if 'output shape' in str(e): skip(aid)\n    else: raise","preventionTips":["Reindex outputs to close's index/columns before returning","Never dropna on axes inside factors"],"tags":["shape-validation","pandas","contract"],"backgroundTag":"dataframe-shape-mismatch","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}