code: def transform_series(
      series: pd.Series,
      transformer,
      fit: bool = False,
      inverse_transform: bool = False,
  ) -> Union[pd.Series, pd.DataFrame]:
      """
      Transform raw values of pandas Series with a scikit-learn alike transformer
      (preprocessor). The transformer used must have the following methods: fit,
      transform, fit_transform and inverse_transform. ColumnTransformers are not
      allowed since they do not have inverse_transform method.
  
      Parameters
      ----------
      series : pandas Series
          Series to be transformed.
      transformer : scikit-learn alike transformer (preprocessor).
          scikit-learn alike transformer (preprocessor) with methods: fit, transform,
          fit_transform and inverse_transform. ColumnTransformers are not allowed
          since they do not have inverse_transform method.
      fit : bool, default `False`
          Train the transformer before applying it.
      inverse_transform : bool, default `False`
          Transform back the data to the original representation.
  
      Returns
      -------
      series_transformed : pandas Series, pandas DataFrame
          Transformed Series. Depending on the transformer used, the output may
          be a Series or a DataFrame.
  
      """
  
      if not isinstance(series, pd.Series):
          raise TypeError(
              (
                  f"`series` argument must be a pandas Series. Got {type(series)}."
              )
          )
  
      if transformer is None:
          return series
  
      if series.name is None:
          series.name = "no_name"
  
      data = series.to_frame()
  
      if fit and hasattr(transformer, "fit"):
          transformer.fit(data)
  
      # If argument feature_names_in_ exits, is overwritten to allow using the
      # transformer on other series than those that were passed during fit.
      if (
          hasattr(transformer, "feature_names_in_")
          and transformer.feature_names_in_[0] != data.columns[0]
      ):
          transformer = deepcopy(transformer)
          transformer.feature_names_in_ = np.array(
              [data.columns[0]], dtype=object
          )
  
      if inverse_transform:
          values_transformed = transformer.inverse_transform(data)
      else:
          values_transformed = transformer.transform(data)
  
      if hasattr(values_transformed, "toarray"):
          # If the returned values are in sparse matrix format, it is converted to dense array.
          values_transformed = values_transformed.toarray()
  
      if (
          isinstance(values_transformed, np.ndarray)
          and values_transformed.shape[1] == 1
      ):
          series_transformed = pd.Series(
              data=values_transformed.flatten(),
              index=data.index,
              name=data.columns[0],
          )
      elif (
          isinstance(values_transformed, pd.DataFrame)
          and values_transformed.shape[1] == 1
      ):
          series_transformed = values_transformed.squeeze()
      else:
          series_transformed = pd.DataFrame(
              data=values_transformed,
              index=data.index,
              columns=transformer.get_feature_names_out(),
          )
  
      return series_transformed
  
imports: from typing import Union, Any, Optional, Tuple, Callable
  import warnings
  import importlib
  import joblib
  import numpy
  import pandas
  import sklearn
  import sklearn.pipeline
  import sklearn.linear_model
  from sklearn.compose import ColumnTransformer
  from sklearn.exceptions import NotFittedError
  import inspect
  from copy import deepcopy
  import skforecast
  from ..exceptions import MissingValuesExogWarning
  from ..exceptions import DataTypeWarning
  from ..exceptions import IgnoredArgumentWarning
  from ..exceptions import SkforecastVersionWarning
label_desc: Use image node_id 18 for calling a global function with example usage: transform_series(series, transformer, fit, inverse_transform) and returns: series_transformed, series