def _transform_static_covs(
        series: TimeSeries,
        fitted_params: dict[str, Any],
        method: Literal["transform", "inverse_transform"],
    ):
        """
        Transforms the static covariates of a `series` if `method = 'transform'`, and inverse
        transforms the static covariates of a `series` if `method = 'inverse_transform'`.
        """

        # Unpack parameters:
        transformer_num = fitted_params["transformer_num"]
        transformer_cat = fitted_params["transformer_cat"]
        mask_num = fitted_params["mask_num"][method]
        mask_cat = fitted_params["mask_cat"][method]
        col_map_cat = fitted_params["col_map_cat"][method]
        n_cat_cols = fitted_params["n_cat_cols"][method]

        vals_num, vals_cat = StaticCovariatesTransformer._extract_static_covs(
            series, mask_num, mask_cat
        )

        # quick check if everything is in order
        n_vals_cat_cols = 0 if vals_cat is None else vals_cat.shape[1]
        if (method == "inverse_transform") and (n_vals_cat_cols != n_cat_cols):
            raise_log(
                ValueError(
                    f"Expected `{n_cat_cols}` categorical value columns but only encountered `{n_vals_cat_cols}`"
                ),
                logger,
            )

        # Transform static covs:
        tr_out_num, tr_out_cat = None, None
        if mask_num.any():
            tr_out_num = getattr(transformer_num, method)(vals_num)
        if mask_cat.any():
            tr_out_cat = getattr(transformer_cat, method)(vals_cat)
            # sparse one hot encoding to dense array
            if isinstance(tr_out_cat, csr_matrix):
                tr_out_cat = tr_out_cat.toarray()

        series = StaticCovariatesTransformer._add_back_static_covs(
            series, tr_out_num, tr_out_cat, mask_num, mask_cat, col_map_cat
        )

        return series

        Transforms the static covariates of a `series` if `method = 'transform'`, and inverse
        transforms the static covariates of a `series` if `method = 'inverse_transform'`.
        
darts/dataprocessing/transformers/static_covariates_transformer.py