Skip to content

check_forecaster_not_fitted_error

yohou.testing.check_forecaster_not_fitted_error(forecaster, y, X_actual=None)

Check accessing fitted attributes before fit() raises NotFittedError.

Parameters

Name Type Description Default
forecaster BaseForecaster

Unfitted forecaster instance

required
y DataFrame

Unused; retained for API uniformity with other check functions.

required
X_actual DataFrame

Unused; retained for API uniformity with other check functions.

None

Raises

Type Description
AssertionError

If NotFittedError is not raised when accessing fitted attributes

Source Code

Source code in src/yohou/testing/forecaster.py
def check_forecaster_not_fitted_error(forecaster, y: pl.DataFrame, X_actual: pl.DataFrame | None = None) -> None:
    """Check accessing fitted attributes before fit() raises NotFittedError.

    Parameters
    ----------
    forecaster : BaseForecaster
        Unfitted forecaster instance
    y : pl.DataFrame
        Unused; retained for API uniformity with other check functions.
    X_actual : pl.DataFrame, optional
        Unused; retained for API uniformity with other check functions.

    Raises
    ------
    AssertionError
        If NotFittedError is not raised when accessing fitted attributes

    """
    forecaster_clone = clone(forecaster)

    # Should raise NotFittedError when checking if fitted
    try:
        check_is_fitted(forecaster_clone, "fit_forecasting_horizon_")
        raise AssertionError(
            f"{forecaster_clone.__class__.__name__} should raise NotFittedError "
            f"when accessing fit_forecasting_horizon_ before fit()"
        )
    except NotFittedError:
        # Expected behavior
        pass