Skip to content

check_panel_invalid_group_raises

yohou.testing.check_panel_invalid_group_raises(forecaster, y_panel)

Check that an invalid group name raises ValueError.

Validates error handling when groups specifies group names that were not seen during fit.

Parameters

Name Type Description Default
forecaster BaseForecaster

Fitted forecaster with panel data

required
y_panel DataFrame

Panel data with panel columns for testing

required

Raises

Type Description
AssertionError

If ValueError is not raised for invalid group

Source Code

Source code in src/yohou/testing/panel.py
def check_panel_invalid_group_raises(forecaster, y_panel: pl.DataFrame) -> None:
    """Check that an invalid group name raises ValueError.

    Validates error handling when ``groups`` specifies group names that
    were not seen during fit.

    Parameters
    ----------
    forecaster : BaseForecaster
        Fitted forecaster with panel data
    y_panel : pl.DataFrame
        Panel data with panel columns for testing

    Raises
    ------
    AssertionError
        If ValueError is not raised for invalid group

    """
    _, y_panel_groups = inspect_panel(y_panel)

    if len(y_panel_groups) > 0:
        # Try to predict with invalid group name
        try:
            _call_predict(forecaster, forecasting_horizon=3, groups=["invalid_group"])
            raise AssertionError("predict() should raise ValueError for an invalid group name, but didn't")
        except ValueError as e:
            # Expected - the message must name the offending group so callers can act on it.
            assert "invalid_group" in str(e), f"ValueError should name the invalid group in the message, got: {e}"