def _check_valid_input(
    model,
    input_type: str,
    series: Sequence[TimeSeries],
    past_covariates: Optional[Sequence[TimeSeries]],
    future_covariates: Optional[Sequence[TimeSeries]],
    target_components: Optional[list[str]],
    past_covariates_components: Optional[list[str]],
    future_covariates_components: Optional[list[str]],
    check_component_names: bool = False,
    requires_input: bool = False,
    test_stationarity: bool = False,
):
    """Checks that the input is valid"""
    if test_stationarity and series is not None:
        if not _test_stationarity(series):
            logger.warning(
                "At least one component of the target series is not stationary. "
                "Beware of wrong interpretation of the chosen explainability."
            )

    if input_type not in ["background", "foreground"]:
        raise_log(
            ValueError(
                f"Unknown `input_type='{input_type}'`. Must be one of ['background', 'foreground']."
            ),
            logger,
        )
    if past_covariates is not None:
        raise_if_not(
            len(series) == len(past_covariates),
            f"The number of {input_type} series and past covariates must be the same.",
            logger,
        )

    if future_covariates is not None:
        raise_if_not(
            len(series) == len(future_covariates),
            f"The number of {input_type} series and future covariates must be the same.",
            logger,
        )

    if requires_input:
        raise_if(
            model.uses_past_covariates and past_covariates is None,
            f"A {input_type} past covariates is not provided, but the model requires past covariates.",
            logger,
        )
        raise_if(
            model.uses_future_covariates and future_covariates is None,
            f"A {input_type} future covariates is not provided, but the model requires future covariates.",
            logger,
        )

    if not check_component_names:
        return

    # ensure we have the same names between TimeSeries (if list of). Important to ensure homogeneity
    # for explained features.
    for idx in range(len(series)):
        raise_if_not(
            all([
                series[idx].columns.to_list() == target_components,
                (
                    past_covariates[idx].columns.to_list() == past_covariates_components
                    if past_covariates is not None
                    else True
                ),
                (
                    future_covariates[idx].columns.to_list()
                    == future_covariates_components
                    if future_covariates is not None
                    else True
                ),
            ]),
            "Columns names must be identical between TimeSeries list components (multi-TimeSeries).",
        )
Checks that the input is valid
darts/explainability/utils.py