Skip to content

check_forecaster_not_fitted_error

yohou.testing.forecaster.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

Test target data

required
X_actual DataFrame

Test features

None

Raises

Type Description
AssertionError

If NotFittedError is not raised when accessing fitted attributes

Source Code

Show/Hide source
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
        Test target data
    X_actual : pl.DataFrame, optional
        Test features

    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