def _extract_sample_weight(sample_weight, target_series):
    """Extracts sample weights values from the time intersection with the target labels."""
    if sample_weight is None:
        return None

    sample_weight_vals = sample_weight.slice_intersect_values(target_series, copy=False)
    if len(sample_weight_vals) != len(target_series):
        raise_log(
            ValueError(
                "The `sample_weight` series must have at least the same times as the target `series`."
            ),
            logger=logger,
        )

    weight_n_comp = sample_weight_vals.shape[1]
    series_n_comp = target_series.n_components
    if weight_n_comp > 1 and weight_n_comp != series_n_comp:
        raise_log(
            ValueError(
                "The number of components in `sample_weight` must either be `1` or match "
                f"the number of target series components `{series_n_comp}`."
            ),
            logger=logger,
        )
    elif weight_n_comp != series_n_comp:
        sample_weight_vals = sample_weight_vals.repeat(series_n_comp, axis=1)
    return sample_weight_vals
Extracts sample weights values from the time intersection with the target labels.
darts/utils/data/tabularization/tabularization.py