def apply_component_mask(
        series: TimeSeries,
        component_mask: Optional[np.ndarray] = None,
        return_ts: bool = False,
    ) -> Union[TimeSeries, Sequence[TimeSeries], np.ndarray, Sequence[np.ndarray]]:
        """
        Extracts components specified by `component_mask` from `series`

        Parameters
        ----------
        series
            input TimeSeries to be fed into transformer.
        component_mask
            Optionally, np.ndarray boolean mask of shape (n_components, 1) specifying which components to
            extract from `series`. The `i`th component of `series` is kept only if `component_mask[i] = True`.
            If not specified, no masking is performed.
        return_ts
            Optionally, specifies that a `TimeSeries` should be returned, rather than an `np.ndarray`.

        Returns
        -------
        masked
            `TimeSeries` (if `return_ts = True`) or `np.ndarray` (if `return_ts = False`) with only those components
            specified by `component_mask` remaining.

        """
        sequence_type_in = get_series_seq_type(series)
        called_with_single_series = sequence_type_in == SeriesType.SINGLE
        series = series2seq(series)

        if component_mask is None:
            if return_ts:
                out = series.copy()
            else:
                out = [series_.all_values() for series_ in series]
            return out[0] if called_with_single_series else out

        if not (
            isinstance(component_mask, np.ndarray) and component_mask.dtype == bool
        ):
            raise_log(
                ValueError(
                    f"`component_mask` must be a boolean `np.ndarray`, not a {type(component_mask)}."
                ),
                logger=logger,
            )

        out = []
        for series_ in series:
            if not series_.width == len(component_mask):
                raise_log(
                    ValueError(
                        "mismatch between number of components in `series` and length of `component_mask`"
                    ),
                    logger=logger,
                )
            if return_ts:
                out_ = series_[series_.columns[component_mask].tolist()]
            else:
                out_ = series_.all_values(copy=False)[:, component_mask, :]
            out.append(out_)
        return out[0] if called_with_single_series else out

        Extracts components specified by `component_mask` from `series`

        Parameters
        ----------
        series
            input TimeSeries to be fed into transformer.
        component_mask
            Optionally, np.ndarray boolean mask of shape (n_components, 1) specifying which components to
            extract from `series`. The `i`th component of `series` is kept only if `component_mask[i] = True`.
            If not specified, no masking is performed.
        return_ts
            Optionally, specifies that a `TimeSeries` should be returned, rather than an `np.ndarray`.

        Returns
        -------
        masked
            `TimeSeries` (if `return_ts = True`) or `np.ndarray` (if `return_ts = False`) with only those components
            specified by `component_mask` remaining.

        
darts/dataprocessing/transformers/base_data_transformer.py