HKUDS/Vibe-Trading · error · ValueError

vif_test needs at least one column

Error message

vif_test needs at least one column

What it means

vif_test requires the design matrix X to have at least one column; an empty (n, 0) frame cannot produce variance inflation factors. The check runs after statsmodels is imported and before any per-column VIF computation.

Source

Thrown at agent/src/quantlib/timeseries.py:754

        severe_threshold: VIF strictly above which collinearity is flagged
            severe. A VIF exactly on the threshold is not flagged.
        watch_threshold: VIF strictly above which collinearity is flagged as
            worth watching. A VIF exactly on the threshold is not flagged.

    Returns:
        DataFrame with one row per column of ``X`` and columns ``feature``
        (str), ``VIF`` (float) and ``concern`` (str, one of ``'severe'`` /
        ``'watch'`` / ``'normal'``).

    Raises:
        ImportError: If ``statsmodels`` is not installed.
        ValueError: If ``X`` has no columns.
    """
    influence = _require(
        "statsmodels.stats.outliers_influence", "statsmodels", "vif_test"
    )
    if X.shape[1] == 0:
        raise ValueError("vif_test needs at least one column")

    values = np.asarray(X, dtype=float)
    vifs = [float(influence.variance_inflation_factor(values, i)) for i in range(X.shape[1])]

    return pd.DataFrame(
        {
            "feature": list(X.columns),
            "VIF": vifs,
            "concern": [
                "severe" if v > severe_threshold else "watch" if v > watch_threshold else "normal"
                for v in vifs
            ],
        }
    )


def bootstrap_statistic(
    data: np.ndarray,

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Verify X.shape[1] > 0 before calling vif_test.
  2. Fix the upstream filter that removed every column.
  3. If no features is legitimately possible, skip the VIF stage conditionally.

Example fix

// before
vif_test(X_filtered)  # all columns were dropped by a variance filter
// after
if X_filtered.shape[1] == 0:
    return pd.DataFrame(columns=["feature", "vif"])
vif_test(X_filtered)
Defensive patterns

Strategy: validation

Validate before calling

assert X.shape[1] > 0, f"vif_test needs columns, got shape {X.shape}"
vif_test(X)

Type guard

def has_columns(X) -> bool:
    return getattr(X, "shape", (0, 0))[1] > 0

Prevention

When it happens

Trigger: vif_test(pd.DataFrame()) or vif_test(np.empty((100, 0))); commonly a feature-selection step removed all columns before the VIF pass.

Common situations: Pipelines that drop columns by variance/threshold filters and end up with none; empty config-driven feature lists; slicing bugs producing zero-width frames.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/9891464f0f3704ab. Report an issue: GitHub.