Skip to content

check_search_panel_data

yohou.testing.check_search_panel_data(search_cv, y_test, groups=None, X_future=None, X_forecast=None)

Check groups parameter propagates correctly.

Parameters

Name Type Description Default
search_cv BaseSearchCV

Fitted search CV instance with panel data

required
y_test DataFrame

Test target data with panel groups

required
groups list of str

Panel group names to test

None
X_future DataFrame

Known-future features forwarded to predict()

None
X_forecast DataFrame

External forecast features forwarded to predict()

None

Raises

Type Description
AssertionError

If groups doesn't propagate correctly

Source Code

Source code in src/yohou/testing/search.py
def check_search_panel_data(
    search_cv,
    y_test: pl.DataFrame,
    groups: list[str] | None = None,
    X_future: pl.DataFrame | None = None,
    X_forecast: pl.DataFrame | None = None,
) -> None:
    """Check groups parameter propagates correctly.

    Parameters
    ----------
    search_cv : BaseSearchCV
        Fitted search CV instance with panel data
    y_test : pl.DataFrame
        Test target data with panel groups
    groups : list of str, optional
        Panel group names to test
    X_future : pl.DataFrame, optional
        Known-future features forwarded to predict()
    X_forecast : pl.DataFrame, optional
        External forecast features forwarded to predict()

    Raises
    ------
    AssertionError
        If groups doesn't propagate correctly

    """
    forecasting_horizon = min(3, len(y_test))

    # Test predict with groups
    y_pred = search_cv.predict(
        forecasting_horizon=forecasting_horizon, groups=groups, X_future=X_future, X_forecast=X_forecast
    )

    # Check that predictions have panel structure if expected
    if groups is not None:
        # Predictions should only include specified groups

        _, panel_groups = inspect_panel(y_pred)

        # Check that all requested groups are present (exact group-key match;
        # panel keys follow the exact group__column naming contract).
        pred_group_prefixes = set(panel_groups.keys())
        for group_name in groups:
            assert group_name in pred_group_prefixes, (
                f"Requested panel group '{group_name}' not found in predictions {pred_group_prefixes}"
            )