Skip to content

check_forecasting_horizon_positive

yohou.utils.validation.check_forecasting_horizon_positive(horizon, allow_none=False)

Validate forecasting horizon is positive.

Parameters

Name Type Description Default
horizon int or None

Forecasting horizon value.

required
allow_none bool

Whether None is acceptable (for predict with optional horizon override).

False

Raises

Type Description
ValueError

If horizon is not positive or is None when not allowed.

See Also

Source Code

Show/Hide source
def check_forecasting_horizon_positive(
    horizon: int | None,
    allow_none: bool = False,
) -> None:
    """Validate forecasting horizon is positive.

    Parameters
    ----------
    horizon : int or None
        Forecasting horizon value.
    allow_none : bool, default=False
        Whether None is acceptable (for predict with optional horizon override).

    Raises
    ------
    ValueError
        If horizon is not positive or is None when not allowed.

    See Also
    --------
    - [`check_X_actual_required`][yohou.utils.validation.check_X_actual_required] : Validate X_actual is provided for recursive prediction.
    - [`check_sufficient_rows`][yohou.utils.validation.check_sufficient_rows] : Validate DataFrame has enough rows for an operation.

    """
    if horizon is None:
        if not allow_none:
            raise ValueError("forecasting_horizon cannot be None")
        return

    if horizon < 1:
        raise ValueError(f"forecasting_horizon must be >= 1, got {horizon}")