class_docstr: Transformer base class.
class_docstr_tok: ["Transformer","base","class","."]
docstr: Convert transform or inverse_transform output to expected format.
  
  Parameters
  ----------
  X : output of _transform or _vectorize("transform"), or inverse variants
  metadata : dict, output of _check_X_y
  inverse : bool, optional, default = False
      whether conversion is for transform (False) or inverse_transform (True)
  
  Returns
  -------
  Xt : final output of transform or inverse_transform
code: def _convert_output(self, X, metadata, inverse=False):
      """Convert transform or inverse_transform output to expected format.
  
      Parameters
      ----------
      X : output of _transform or _vectorize("transform"), or inverse variants
      metadata : dict, output of _check_X_y
      inverse : bool, optional, default = False
          whether conversion is for transform (False) or inverse_transform (True)
  
      Returns
      -------
      Xt : final output of transform or inverse_transform
      """
      # skip conversion if not both conversions are switched on
      configs = self.get_config()
      input_conv = configs["input_conversion"]
      output_conv = configs["output_conversion"]
      if input_conv != "on" or output_conv != "on":
          return X
  
      Xt = X
      X_input_mtype = metadata["_X_mtype_last_seen"]
      X_input_scitype = metadata["_X_input_scitype"]
      case = metadata["_convert_case"]
      _converter_store_X = metadata["_converter_store_X"]
  
      if inverse:
          # the output of inverse transform is equal to input of transform
          output_scitype = self.get_tag("scitype:transform-input")
      else:
          output_scitype = self.get_tag("scitype:transform-output")
  
      # if we converted Series to "one-instance-Panel/Hierarchical",
      #   or Panel to "one-instance-Hierarchical", then revert that
      # remainder is as in case 1
      #   skipped for output_scitype = "Primitives"
      #       since then the output always is a pd.DataFrame
      if (
          case == "case 2: higher scitype supported"
          and output_scitype == "Series"
      ):
          if self.get_tags()["scitype:transform-input"] == "Panel":
              # Conversion from Series to Panel done for being compatible with
              # algorithm. Thus, the returned Series should stay a Series.
              pass
          else:
              Xt = convert_to(
                  Xt,
                  to_type=[
                      "pd-multiindex",
                      "numpy3D",
                      "df-list",
                      "pd_multiindex_hier",
                  ],
              )
          Xt = convert_to_scitype(Xt, to_scitype=X_input_scitype)
  
      # now, in all cases, Xt is in the right scitype,
      #   but not necessarily in the right mtype.
      # additionally, Primitives may have an extra column
  
      #   "case 1: scitype supported"
      #   "case 2: higher scitype supported"
      #   "case 3: requires vectorization"
  
      if output_scitype == "Series":
          # output mtype is input mtype
          X_output_mtype = X_input_mtype
          # exception to this: if the transformer outputs multivariate series,
          #   we cannot convert back to pd.Series, do pd.DataFrame instead then
          #   this happens only for Series, not Panel
          if X_input_scitype == "Series":
              if X_input_mtype == "pd.Series":
                  Xt_metadata_required = ["is_univariate"]
              else:
                  Xt_metadata_required = []
  
              valid, msg, metadata = check_is_mtype(
                  Xt,
                  ["pd.DataFrame", "pd.Series", "np.ndarray"],
                  msg_return_dict="list",
                  return_metadata=Xt_metadata_required,
              )
  
              if not valid:
                  raise TypeError(
                      f"_transform output of {type(self)} does not comply "
                      "with sktime mtype specifications. See datatypes.MTYPE_REGISTER"
                      " for mtype specifications. Returned error message:"
                      f" {msg}. Returned object: {Xt}"
                  )
              if (
                  X_input_mtype == "pd.Series"
                  and not metadata["is_univariate"]
              ):
                  X_output_mtype = "pd.DataFrame"
          elif self.get_tags()["scitype:transform-input"] == "Panel":
              # Input has always to be Panel
              X_output_mtype = "pd.DataFrame"
          else:
              # Input can be Panel or Hierarchical, since it is supported
              # by the used mtype
              output_scitype = X_input_scitype
              # Xt_mtype = metadata["mtype"]
          # else:
          #     Xt_mtype = X_input_mtype
  
          # Xt = convert(
          #     Xt,
          #     from_type=Xt_mtype,
          #     to_type=X_output_mtype,
          #     as_scitype=X_input_scitype,
          #     store=_converter_store_X,
          #     store_behaviour="freeze",
          # )
          return convert_to(
              Xt,
              to_type=X_output_mtype,
              as_scitype=output_scitype,
              store=_converter_store_X,
              store_behaviour="freeze",
          )
      elif output_scitype == "Primitives":
          # we ensure the output is pd_DataFrame_Table
          # & ensure the returned index is sensible
          # for return index, we need to deal with last level, constant 0
          if isinstance(Xt, (pd.DataFrame, pd.Series)):
              # if index is multiindex, last level is constant 0
              # and other levels are hierarchy
              if isinstance(Xt.index, pd.MultiIndex):
                  Xt.index = Xt.index.droplevel(-1)
              # else this is only zeros and should be reset to RangeIndex
              else:
                  Xt = Xt.reset_index(drop=True)
          return convert_to(
              Xt,
              to_type="pd_DataFrame_Table",
              as_scitype="Table",
              # no converter store since this is not a "1:1 back-conversion"
          )
      # else output_scitype is "Panel" and no need for conversion
  
      return Xt
  
imports: from itertools import product
  from typing import Union
  import numpy
  import pandas
  from sktime.base import BaseEstimator
  from sktime.datatypes import VectorizedDF, check_is_error_msg, check_is_mtype, check_is_scitype, convert, convert_to, mtype_to_scitype, update_data
  from sktime.datatypes._series_as_panel import convert_to_scitype
  from sktime.utils.sklearn import is_sklearn_classifier, is_sklearn_clusterer, is_sklearn_regressor, is_sklearn_transformer
  from sktime.utils.validation._dependencies import _check_estimator_deps
label_desc: Use image node_id 18 for calling the BaseTransformer obj's underlying member method code with example usage: obj._convert_output(X, metadata, inverse) and returns: Xt, X, convert_to, convert_to