Skip to content

check_metadata_routing_get_metadata_routing

yohou.testing.common.check_metadata_routing_get_metadata_routing(estimator_fitted)

Check that get_metadata_routing() is implemented correctly.

Tests: - Method exists and returns MetadataRouter or MetadataRequest - Router has correct owner - Router includes child estimators if applicable

Parameters

Name Type Description Default
estimator_fitted BaseForecaster | BaseTransformer

A fitted estimator instance

required

Raises

Type Description
AssertionError

If get_metadata_routing implementation is incorrect

Source Code

Show/Hide source
def check_metadata_routing_get_metadata_routing(estimator_fitted) -> None:
    """Check that get_metadata_routing() is implemented correctly.

    Tests:
    - Method exists and returns MetadataRouter or MetadataRequest
    - Router has correct owner
    - Router includes child estimators if applicable

    Parameters
    ----------
    estimator_fitted : BaseForecaster | BaseTransformer
        A fitted estimator instance

    Raises
    ------
    AssertionError
        If get_metadata_routing implementation is incorrect

    """
    assert hasattr(estimator_fitted, "get_metadata_routing"), (
        f"{type(estimator_fitted).__name__} must implement get_metadata_routing()"
    )

    router = estimator_fitted.get_metadata_routing()

    assert isinstance(router, MetadataRouter | MetadataRequest), (
        f"get_metadata_routing() must return MetadataRouter or MetadataRequest, got {type(router)}"
    )

    # Check owner is set
    assert router.owner is not None, "Router must have an owner set"