{"record":{"id":"97460adfec92bcdd","repo":"HKUDS/Vibe-Trading","slug":"bootstrap-statistic-needs-a-non-empty-sample","errorCode":null,"errorMessage":"bootstrap_statistic needs a non-empty sample","messagePattern":"bootstrap_statistic needs a non-empty sample","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/timeseries.py","lineNumber":802,"sourceCode":"\n    Args:\n        data: One-dimensional sample of observations.\n        statistic_func: Callable mapping a resample to a scalar, e.g. ``np.mean``.\n        n_bootstrap: Number of bootstrap resamples.\n        confidence: Confidence level in (0, 1), e.g. 0.95 for a 95% interval.\n        seed: Seed for the random generator; pass an int for reproducible output.\n\n    Returns:\n        Dict with keys ``point_estimate``, ``bootstrap_mean``, ``bootstrap_std``,\n        ``ci_lower``, ``ci_upper`` (all float) and ``confidence`` (float, echoed).\n\n    Raises:\n        ValueError: If ``data`` is empty, ``n_bootstrap`` is below 1, or\n            ``confidence`` is not strictly inside (0, 1).\n    \"\"\"\n    sample = np.asarray(data, dtype=float).ravel()\n    if sample.size == 0:\n        raise ValueError(\"bootstrap_statistic needs a non-empty sample\")\n    if n_bootstrap < 1:\n        raise ValueError(f\"bootstrap_statistic needs n_bootstrap >= 1, got {n_bootstrap}\")\n    if not 0.0 < confidence < 1.0:\n        raise ValueError(f\"bootstrap_statistic needs confidence in (0, 1), got {confidence}\")\n\n    rng = np.random.default_rng(seed)\n    n = sample.size\n    # Resample one draw at a time. Materialising the whole (n_bootstrap, n)\n    # index matrix would be ~160MB at the default 10000 draws over 2000 bars.\n    bootstrap_stats = np.empty(n_bootstrap, dtype=float)\n    for i in range(n_bootstrap):\n        bootstrap_stats[i] = float(statistic_func(sample[rng.integers(0, n, size=n)]))\n\n    alpha = 1 - confidence\n    return {\n        \"point_estimate\": float(statistic_func(sample)),\n        \"bootstrap_mean\": float(np.mean(bootstrap_stats)),\n        \"bootstrap_std\": float(np.std(bootstrap_stats)),","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/timeseries.py#L784-L820","documentation":"bootstrap_statistic refuses an empty sample: np.asarray(data).ravel() must yield at least one element, otherwise resampling and percentile confidence intervals are undefined.","triggerScenarios":"bootstrap_statistic([]) or passing a returns array filtered down to zero rows (e.g. returns[returns > 0.5] matching nothing); an empty pandas Series or column.","commonSituations":"Date-range or mask filters that match no rows, empty ticker histories, downstream of dropna removing everything.","solutions":["Check sample.size > 0 before calling.","Debug why the filter/mask producing the data matched zero rows.","Fall back to a default window or skip bootstrapping when data is unavailable."],"exampleFix":"// before\nbootstrap_statistic(returns[mask])  # mask matches nothing\n// after\nif len(returns[mask]) == 0:\n    return None\nbootstrap_statistic(returns[mask])","handlingStrategy":"validation","validationCode":"import numpy as np\nif np.asarray(data).size == 0:\n    raise ValueError(\"no data to bootstrap\")\nbootstrap_statistic(data, ...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check len(data) > 0 after masks/filters.","Log row counts before expensive diagnostic stages so empty inputs are visible."],"tags":["python","statistics","bootstrap","empty-data"],"backgroundTag":"empty-data-argument","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}