class_docstr: Wrapper for easy vectorization/iteration over instances.
  
  VectorizedDF is an iterable that returns pandas.DataFrame
      in sktime Series or Panel format.
  Elements are all Series or Panels in X, these are iterated over.
  
  Parameters
  ----------
  X : object in sktime compatible Panel or Hierarchical format
      the data container to vectorize over
  y : placeholder argument, not used currently
  is_scitype : str ("Panel", "Hierarchical") or None, default = "Panel"
      scitype of X, if known; if None, will be inferred
      provide to constructor if known to avoid superfluous checks
          Caution: will not conduct checks if provided, assumes checks done
  iterate_as : str ("Series", "Panel"), optional, default="Series
      scitype of the iteration
      for instance, if X is Panel and iterate_as is "Series"
          then the class will iterate over individual Series in X
      or, if X is Hierarchical and iterate_as is "Panel"
          then the class will iterate over individual Panels in X
              (Panel = flat/non-hierarchical collection of Series)
  iterate_cols : boolean, optional, default=False
      whether to iterate over columns, if true, the class will iterate over columns
  
  Methods
  -------
  iter(self) or self.__iter__()
      Iterates over each Series/Panel (depending on iterate_as) in X
      as pandas.DataFrame with Index or MultiIndex (in sktime pandas format)
  len(self) or self.__len__()
      returns number of Series/Panels in X
  get_iter_indices()
      Returns pandas.(Multi)Index that are iterated over
  reconstruct(self, df_list, convert_back=False)
      Takes iterable df_list and returns as an object of is_scitype.
      Used to obtain original format after applying operations to self iterated
class_docstr_tok: ["Wrapper","for","easy","vectorization\/iteration","over","instances",".","VectorizedDF","is","an","iterable","that","returns","pandas.DataFrame","in","sktime","Series","or","Panel","format",".","Elements","are","all","Series","or","Panels","in","X",",","these","are","iterated","over",".","Parameters","--","--","--","--","--","X",":","object","in","sktime","compatible","Panel","or","Hierarchical","format","the","data","container","to","vectorize","over","y",":","placeholder","argument",",","not","used","currently","is_scitype",":","str","(","``","Panel","''",",","``","Hierarchical","''",")","or","None",",","default","=","``","Panel","''","scitype","of","X",",","if","known",";","if","None",",","will","be","inferred","provide","to","constructor","if","known","to","avoid","superfluous","checks","Caution",":","will","not","conduct","checks","if","provided",",","assumes","checks","done","iterate_as",":","str","(","``","Series","''",",","``","Panel","''",")",",","optional",",","default=","''","Series","scitype","of","the","iteration","for","instance",",","if","X","is","Panel","and","iterate_as","is","``","Series","''","then","the","class","will","iterate","over","individual","Series","in","X","or",",","if","X","is","Hierarchical","and","iterate_as","is","``","Panel","''","then","the","class","will","iterate","over","individual","Panels","in","X","(","Panel","=","flat\/non-hierarchical","collection","of","Series",")","iterate_cols",":","boolean",",","optional",",","default=False","whether","to","iterate","over","columns",",","if","true",",","the","class","will","iterate","over","columns","Methods","--","--","--","-","iter","(","self",")","or","self.__iter__","(",")","Iterates","over","each","Series\/Panel","(","depending","on","iterate_as",")","in","X","as","pandas.DataFrame","with","Index","or","MultiIndex","(","in","sktime","pandas","format",")","len","(","self",")","or","self.__len__","(",")","returns","number","of","Series\/Panels","in","X","get_iter_indices","(",")","Returns","pandas",".","(","Multi",")","Index","that","are","iterated","over","reconstruct","(","self",",","df_list",",","convert_back=False",")","Takes","iterable","df_list","and","returns","as","an","object","of","is_scitype",".","Used","to","obtain","original","format","after","applying","operations","to","self","iterated"]
docstr: Vectorize application of estimator method, return results DataFrame or list.
  
  This function returns a `pd.DataFrame` with `estimator` fitted on
  vectorization slices of `self`. Row and column indices are the
  same as obtained from `get_iter_indices`.
  
  This function:
  
  1. takes a single `sktime` estimator or a `pd.DataFrame` with estimator entries
  2. calls `method` of estimator, with arguments as per `args`, `args_rowvec`
  3. returns the result, a list or pd.DataFrame with estimator values
  
  If `estimator` is a single estimator, it is broadcast to a `pd.DataFrame`.
  Elements of `args`, `args_rowvec` can be `VectorizedDF`, in which case
  they are broadcast in the application step 2.
  
  For a row and column of the return,
  the entry is `estimator` at the same entry (if `DataFrame`) or `estimator`,
  where `method` has been executed with the following arguments:
  
  * `varname=value`, where `varname`/`value` are key-value pair of `kwargs`,
    and `value` is not an instance of `VectorizedDF`, for all such `value`
  * `varname=value.loc[row,col]`,
    where `varname`/`value` are key-value pair of `kwargs` or `args`,
    and `row` and `col` are `loc` indices corresponding to row/column,
    and `value` is an instance of `VectorizedDF`, for all such `value`
  * `varname=value.loc[row]`,
    where `varname`/`value` are key-value pair of `args_rowvec`,
    and `row` and `col` are `loc` indices corresponding to row/column,
    and `value` is an instance of `VectorizedDF`, for all such `value`
  * `varname_of_self=self`, if `varname_of_self` is not `None`. Here,
    `varname_of_self` should be read as the `str` value of that variable.
  
  Parameters
  ----------
  estimator : one of
      a. an sktime estimator object, instance of descendant of BaseEstimator
      b. pd.DataFrame with row/col indices being `self.get_iter_indices()`,
         entries sktime estimator objects, inst. of descendants of BaseEstimator
  method : str, optional, default="clone"
      method of estimator to call with arguments in `args`, `args_rowvec`
  args : dict, optional, default=empty dict
      arguments to pass to `method` of estimator clones
      will vectorize/iterator over rows and columns
  args_rowvec : dict, optional, default=empty dict
      arguments to pass to `method` of estimator clones
      will vectorize/iterator only over rows but not over columns
  return_type : str, one of "pd.DataFrame" or "list"
      the return will be of this type;
      if `pd.DataFrame`, with row/col indices being `self.get_iter_indices()`
      if `list`, entries in sequence corresponding to `self__iter__`
  rowname_default : str, optional, default="estimators"
      used as index name of single row if no row vectorization is performed
  colname_default : str, optional, default="estimators"
      used as index name of single column if no column vectorization is performed
  varname_of_self : str, optional, default=None
      if not None, self will be passed as kwarg under name "varname_of_self"
  backend : {"dask", "loky", "multiprocessing", "threading"}, by default None.
      Runs parallel evaluate if specified and ``strategy`` is set as "refit".
  
      - "None": executes loop sequentally, simple list comprehension
      - "loky", "multiprocessing" and "threading": uses ``joblib.Parallel`` loops
      - "joblib": custom and 3rd party ``joblib`` backends, e.g., ``spark``
      - "dask": uses ``dask``, requires ``dask`` package in environment
      - "dask_lazy": same as "dask", but returns delayed object instead
  
      Parameter is passed to ``utils.parallel.parallelize``.
  
  backend_params : dict, optional
      additional parameters passed to the backend as config.
      Directly passed to ``utils.parallel.parallelize``.
      Valid keys depend on the value of ``backend``:
  
      - "None": no additional parameters, ``backend_params`` is ignored
      - "loky", "multiprocessing" and "threading":
        any valid keys for ``joblib.Parallel`` can be passed here,
        e.g., ``n_jobs``, with the exception of ``backend``
        which is directly controlled by ``backend``
      - "dask": any valid keys for ``dask.compute`` can be passed,
        e.g., ``scheduler``
  
  kwargs : will be passed to invoked methods of estimator(s) in ``estimator``
  
  Returns
  -------
  pd.DataFrame, with rows and columns as the return of ``get_iter_indices``.
    If rows or columns are not vectorized over, the single index
    will be ``rowname_default`` resp ``colname_default``.
    Entries are identity references to entries of ``estimator``,
    after ``method`` executed with arguments as above.
docstr_tok: ["Vectorize","application","of","estimator","method",",","return","results","DataFrame","or","list",".","This","function","returns","a","`","pd.DataFrame","`","with","`","estimator","`","fitted","on","vectorization","slices","of","`","self","`",".","Row","and","column","indices","are","the","same","as","obtained","from","`","get_iter_indices","`",".","This","function",":","1.","takes","a","single","`","sktime","`","estimator","or","a","`","pd.DataFrame","`","with","estimator","entries","2.","calls","`","method","`","of","estimator",",","with","arguments","as","per","`","args","`",",","`","args_rowvec","`","3.","returns","the","result",",","a","list","or","pd.DataFrame","with","estimator","values","If","`","estimator","`","is","a","single","estimator",",","it","is","broadcast","to","a","`","pd.DataFrame","`",".","Elements","of","`","args","`",",","`","args_rowvec","`","can","be","`","VectorizedDF","`",",","in","which","case","they","are","broadcast","in","the","application","step","2",".","For","a","row","and","column","of","the","return",",","the","entry","is","`","estimator","`","at","the","same","entry","(","if","`","DataFrame","`",")","or","`","estimator","`",",","where","`","method","`","has","been","executed","with","the","following","arguments",":","*","`","varname=value","`",",","where","`","varname","`","\/","`","value","`","are","key-value","pair","of","`","kwargs","`",",","and","`","value","`","is","not","an","instance","of","`","VectorizedDF","`",",","for","all","such","`","value","`","*","`","varname=value.loc","[","row",",","col","]","`",",","where","`","varname","`","\/","`","value","`","are","key-value","pair","of","`","kwargs","`","or","`","args","`",",","and","`","row","`","and","`","col","`","are","`","loc","`","indices","corresponding","to","row\/column",",","and","`","value","`","is","an","instance","of","`","VectorizedDF","`",",","for","all","such","`","value","`","*","`","varname=value.loc","[","row","]","`",",","where","`","varname","`","\/","`","value","`","are","key-value","pair","of","`","args_rowvec","`",",","and","`","row","`","and","`","col","`","are","`","loc","`","indices","corresponding","to","row\/column",",","and","`","value","`","is","an","instance","of","`","VectorizedDF","`",",","for","all","such","`","value","`","*","`","varname_of_self=self","`",",","if","`","varname_of_self","`","is","not","`","None","`",".","Here",",","`","varname_of_self","`","should","be","read","as","the","`","str","`","value","of","that","variable",".","Parameters","--","--","--","--","--","estimator",":","one","of","a.","an","sktime","estimator","object",",","instance","of","descendant","of","BaseEstimator","b.","pd.DataFrame","with","row\/col","indices","being","`","self.get_iter_indices","(",")","`",",","entries","sktime","estimator","objects",",","inst",".","of","descendants","of","BaseEstimator","method",":","str",",","optional",",","default=","''","clone","''","method","of","estimator","to","call","with","arguments","in","`","args","`",",","`","args_rowvec","`","args",":","dict",",","optional",",","default=empty","dict","arguments","to","pass","to","`","method","`","of","estimator","clones","will","vectorize\/iterator","over","rows","and","columns","args_rowvec",":","dict",",","optional",",","default=empty","dict","arguments","to","pass","to","`","method","`","of","estimator","clones","will","vectorize\/iterator","only","over","rows","but","not","over","columns","return_type",":","str",",","one","of","``","pd.DataFrame","''","or","``","list","''","the","return","will","be","of","this","type",";","if","`","pd.DataFrame","`",",","with","row\/col","indices","being","`","self.get_iter_indices","(",")","`","if","`","list","`",",","entries","in","sequence","corresponding","to","`","self__iter__","`","rowname_default",":","str",",","optional",",","default=","''","estimators","''","used","as","index","name","of","single","row","if","no","row","vectorization","is","performed","colname_default",":","str",",","optional",",","default=","''","estimators","''","used","as","index","name","of","single","column","if","no","column","vectorization","is","performed","varname_of_self",":","str",",","optional",",","default=None","if","not","None",",","self","will","be","passed","as","kwarg","under","name","``","varname_of_self","''","backend",":","{","``","dask","''",",","``","loky","''",",","``","multiprocessing","''",",","``","threading","''","}",",","by","default","None",".","Runs","parallel","evaluate","if","specified","and","``","strategy","``","is","set","as","``","refit","''",".","-","``","None","''",":","executes","loop","sequentally",",","simple","list","comprehension","-","``","loky","''",",","``","multiprocessing","''","and","``","threading","''",":","uses","``","joblib.Parallel","``","loops","-","``","joblib","''",":","custom","and","3rd","party","``","joblib","``","backends",",","e.g.",",","``","spark","``","-","``","dask","''",":","uses","``","dask","``",",","requires","``","dask","``","package","in","environment","-","``","dask_lazy","''",":","same","as","``","dask","''",",","but","returns","delayed","object","instead","Parameter","is","passed","to","``","utils.parallel.parallelize","``",".","backend_params",":","dict",",","optional","additional","parameters","passed","to","the","backend","as","config",".","Directly","passed","to","``","utils.parallel.parallelize","``",".","Valid","keys","depend","on","the","value","of","``","backend","``",":","-","``","None","''",":","no","additional","parameters",",","``","backend_params","``","is","ignored","-","``","loky","''",",","``","multiprocessing","''","and","``","threading","''",":","any","valid","keys","for","``","joblib.Parallel","``","can","be","passed","here",",","e.g.",",","``","n_jobs","``",",","with","the","exception","of","``","backend","``","which","is","directly","controlled","by","``","backend","``","-","``","dask","''",":","any","valid","keys","for","``","dask.compute","``","can","be","passed",",","e.g.",",","``","scheduler","``","kwargs",":","will","be","passed","to","invoked","methods","of","estimator","(","s",")","in","``","estimator","``","Returns","--","--","--","-","pd.DataFrame",",","with","rows","and","columns","as","the","return","of","``","get_iter_indices","``",".","If","rows","or","columns","are","not","vectorized","over",",","the","single","index","will","be","``","rowname_default","``","resp","``","colname_default","``",".","Entries","are","identity","references","to","entries","of","``","estimator","``",",","after","``","method","``","executed","with","arguments","as","above","."]
code: def vectorize_est(
      self,
      estimator,
      method="clone",
      args=None,
      args_rowvec=None,
      return_type="pd.DataFrame",
      rowname_default="estimators",
      colname_default="estimators",
      varname_of_self=None,
      backend=None,
      backend_params=None,
      **kwargs,
  ):
      """Vectorize application of estimator method, return results DataFrame or list.
  
      This function returns a `pd.DataFrame` with `estimator` fitted on
      vectorization slices of `self`. Row and column indices are the
      same as obtained from `get_iter_indices`.
  
      This function:
  
      1. takes a single `sktime` estimator or a `pd.DataFrame` with estimator entries
      2. calls `method` of estimator, with arguments as per `args`, `args_rowvec`
      3. returns the result, a list or pd.DataFrame with estimator values
  
      If `estimator` is a single estimator, it is broadcast to a `pd.DataFrame`.
      Elements of `args`, `args_rowvec` can be `VectorizedDF`, in which case
      they are broadcast in the application step 2.
  
      For a row and column of the return,
      the entry is `estimator` at the same entry (if `DataFrame`) or `estimator`,
      where `method` has been executed with the following arguments:
  
      * `varname=value`, where `varname`/`value` are key-value pair of `kwargs`,
        and `value` is not an instance of `VectorizedDF`, for all such `value`
      * `varname=value.loc[row,col]`,
        where `varname`/`value` are key-value pair of `kwargs` or `args`,
        and `row` and `col` are `loc` indices corresponding to row/column,
        and `value` is an instance of `VectorizedDF`, for all such `value`
      * `varname=value.loc[row]`,
        where `varname`/`value` are key-value pair of `args_rowvec`,
        and `row` and `col` are `loc` indices corresponding to row/column,
        and `value` is an instance of `VectorizedDF`, for all such `value`
      * `varname_of_self=self`, if `varname_of_self` is not `None`. Here,
        `varname_of_self` should be read as the `str` value of that variable.
  
      Parameters
      ----------
      estimator : one of
          a. an sktime estimator object, instance of descendant of BaseEstimator
          b. pd.DataFrame with row/col indices being `self.get_iter_indices()`,
             entries sktime estimator objects, inst. of descendants of BaseEstimator
      method : str, optional, default="clone"
          method of estimator to call with arguments in `args`, `args_rowvec`
      args : dict, optional, default=empty dict
          arguments to pass to `method` of estimator clones
          will vectorize/iterator over rows and columns
      args_rowvec : dict, optional, default=empty dict
          arguments to pass to `method` of estimator clones
          will vectorize/iterator only over rows but not over columns
      return_type : str, one of "pd.DataFrame" or "list"
          the return will be of this type;
          if `pd.DataFrame`, with row/col indices being `self.get_iter_indices()`
          if `list`, entries in sequence corresponding to `self__iter__`
      rowname_default : str, optional, default="estimators"
          used as index name of single row if no row vectorization is performed
      colname_default : str, optional, default="estimators"
          used as index name of single column if no column vectorization is performed
      varname_of_self : str, optional, default=None
          if not None, self will be passed as kwarg under name "varname_of_self"
      backend : {"dask", "loky", "multiprocessing", "threading"}, by default None.
          Runs parallel evaluate if specified and ``strategy`` is set as "refit".
  
          - "None": executes loop sequentally, simple list comprehension
          - "loky", "multiprocessing" and "threading": uses ``joblib.Parallel`` loops
          - "joblib": custom and 3rd party ``joblib`` backends, e.g., ``spark``
          - "dask": uses ``dask``, requires ``dask`` package in environment
          - "dask_lazy": same as "dask", but returns delayed object instead
  
          Parameter is passed to ``utils.parallel.parallelize``.
  
      backend_params : dict, optional
          additional parameters passed to the backend as config.
          Directly passed to ``utils.parallel.parallelize``.
          Valid keys depend on the value of ``backend``:
  
          - "None": no additional parameters, ``backend_params`` is ignored
          - "loky", "multiprocessing" and "threading":
            any valid keys for ``joblib.Parallel`` can be passed here,
            e.g., ``n_jobs``, with the exception of ``backend``
            which is directly controlled by ``backend``
          - "dask": any valid keys for ``dask.compute`` can be passed,
            e.g., ``scheduler``
  
      kwargs : will be passed to invoked methods of estimator(s) in ``estimator``
  
      Returns
      -------
      pd.DataFrame, with rows and columns as the return of ``get_iter_indices``.
        If rows or columns are not vectorized over, the single index
        will be ``rowname_default`` resp ``colname_default``.
        Entries are identity references to entries of ``estimator``,
        after ``method`` executed with arguments as above.
      """
      iterate_as = self.iterate_as
      iterate_cols = self.iterate_cols
  
      if args is None:
          args = kwargs
      else:
          args = args.copy()
          args.update(kwargs)
  
      if args_rowvec is None:
          args_rowvec = {}
  
      if return_type not in {"pd.DataFrame", "list"}:
          raise ValueError(
              'return_type must be one of "pd.DataFrame" or "list"'
          )
  
      if varname_of_self and not isinstance(varname_of_self, str):
          raise TypeError("varname_of_self must be a string")
  
      def explode(d: dict, iterate_as, iterate_cols):
          if not d:
              yield from itertools.cycle([{}])
  
          def _to_iter(e):
              if isinstance(e, VectorizedDF):
                  it = (
                      inst
                      for _, _, inst in e.items(
                          iterate_as=iterate_as,
                          iterate_cols=iterate_cols,
                      )
                  )
  
                  # repeat group for each column
                  if self.iterate_cols and not iterate_cols:
                      it = itertools.chain.from_iterable(
                          itertools.repeat(el, self.shape[1])
                          for el in it
                      )
  
                  return it
              else:
                  return itertools.cycle([e])
  
          keys, values_with_vec = zip(*d.items())
          for values_inst in zip(*map(_to_iter, values_with_vec)):
              yield dict(zip(keys, values_inst))
  
      if isinstance(estimator, pd.DataFrame):
          if estimator.shape != self.shape:
              raise ValueError(
                  f"The estimator data frame must have the same shape as self. "
                  f"Expected {self.shape}, found {estimator.shape}"
              )
          estimators = (
              cell
              for _, row in estimator.iterrows()
              for cell in row.values
          )
      else:
          estimators = itertools.cycle([estimator])
  
      vec_zip = zip(
          self.items(),
          explode(
              args, iterate_as=iterate_as, iterate_cols=iterate_cols
          ),
          explode(
              args_rowvec, iterate_as=iterate_as, iterate_cols=False
          ),
          estimators,
      )
  
      meta = {
          "method": method,
          "varname_of_self": varname_of_self,
          "rowname_default": rowname_default,
          "colname_default": colname_default,
      }
  
      ret = parallelize(
          fun=self._vectorize_est_single,
          iter=vec_zip,
          meta=meta,
          backend=backend,
          backend_params=backend_params,
      )
  
      if return_type == "pd.DataFrame":
          df_long = pd.DataFrame(ret)
          cols_right_order = df_long.loc[:, 1].unique()
          rows_right_order = df_long.loc[:, 0].unique()
  
          df = df_long.pivot(index=0, columns=1, values=2)
          # DataFrame.pivot sorts the rows & columns
          # (is this a bug? see #4683 and #5108)
          # either way, we need to fix this:
          df = df.reindex(cols_right_order, axis=1)
          df = df.reindex(rows_right_order, axis=0)
  
          # remove "0" and "1" from index/columns name
          df.index.names = [None] * len(df.index.names)
          df.columns.name = None
  
          # TODO: add test case for tuple index
          try:
              df.index = pd.MultiIndex.from_tuples(df.index)
          except TypeError:
              pass
          except ValueError:
              pass
          return df
      else:  # if return_type == "list"
          return [result for _, _, result in ret]
  
imports: import itertools
  import numpy
  import pandas
  from sktime.datatypes._check import check_is_scitype, mtype
  from sktime.datatypes._convert import convert_to
  from sktime.utils.multiindex import flatten_multiindex
  from sktime.utils.parallel import parallelize
label_desc: Use image node_id 17 for calling the VectorizedDF obj's underlying member method code with example usage: obj.vectorize_est(estimator, method, args, args_rowvec, return_type, rowname_default, colname_default, varname_of_backend, backend_params) and returns: df, unknown, it, itertools