code: def _handle_seriesprocessor_func_output(
      func_output: Union[
          np.ndarray, pd.Series, pd.DataFrame, List[pd.Series]
      ],
      required_dict: Dict[str, pd.Series],
      func_name: str,
  ) -> Union[Dict[str, pd.Series], pd.DataFrame]:
      """Handle the output of a SeriesProcessor its function.
  
      Parameters
      ----------
      func_output : Union[np.ndarray, pd.Series, pd.DataFrame, List[pd.Series]]
          The output of the SeriesProcessor its function.
      required_dict : Dict[str, pd.Series]
          The series dict that contains the required series for the `SeriesProcessor` its
          function.
      func_name : str
          The name of the SeriesProcessor (its function).
  
      Returns
      -------
      Union[Dict[str, pd.Series], pd.DataFrame]
          The processed outputs in the given func_output. \n
          * If the `func_output` is a `pd.DataFrame`, the `pd.DataFrame` is returned.
          * If the `func_output` is a `pd.Series`, `np.ndarray`, or list of `pd.Series`,
            a series dict is returned.
  
      Raises
      ------
      TypeError
          Error raised when function output is invalid.
  
      Notes
      -----
      * If `func_output` is a `np.ndarray` or a `pd.Series` without a name, than the given
        `requested_dict` must contain just 1 series! That series its name and index are
        used to  transform (i.e., **replace**) that **series with the numpy array**.
        When a user does not want a numpy array to replace its input series, it is his /
        her responsibility to create a new `pd.Series` (or `pd.DataFrame`) of that numpy
        array with a different (column) name.
      * If `func_output` is a `pd.Series`, keep in mind that the input series gets
        transformed (i.e., **replaced**) with the `func_output` **when the series name is
        equal** or when there is no series name (see note above).
  
      """
      if isinstance(func_output, pd.DataFrame):
          # Nothing has to be done! A pd.DataFrame can be added to a series_dict using
          # series_dict.update(df)
          # Note: converting this to a dictionary (to_dict()) is **very** inefficient!
          # Assert that the DataFrame has a time-index
          if len(func_output):
              assert isinstance(func_output.index, pd.DatetimeIndex)
          # Assert that the DataFrame columns are named
          assert all(
              func_output.columns.values
              != [i for i in range(func_output.shape[1])]
          )
          return func_output
  
      elif isinstance(func_output, pd.Series):
          # Convert series to series_dict and return
          # => if func_output.name is in the required_dict, than the original series will
          #    be replaced by this new series.
          # Assert that the series has a time-index
          if len(func_output):
              assert isinstance(func_output.index, pd.DatetimeIndex)
          # Assert (func_output.name is not None) | (len(required_dict) == 1)
          if func_output.name is None:
              # If a series without a name is returned that is constructed from just 1
              # series => the input series will be replaced by this series
              assert len(required_dict) == 1
              # Rename, but keep the same reference to the data
              input_series = list(required_dict.values())[0]
              func_output.rename(
                  input_series.name, inplace=True, copy=False
              )
          return {str(func_output.name): func_output}
  
      elif isinstance(func_output, np.ndarray):
          # Must be constructed from just 1 series
          # => the input series will be replaced by this array
          assert len(required_dict) == 1
          # Create a series with the same view
          input_series = list(required_dict.values())[0]
          return {
              str(input_series.name): _np_array_to_series(
                  func_output, input_series
              )
          }
  
      elif isinstance(func_output, list) and all(
          [isinstance(el, pd.Series) for el in func_output]
      ):
          # Convert the list of series into a series dict, using the same data reference
          # => if for any series in the list, series.name is in the required_dict, than
          #    the the original series will be replaced by this new series.
          # Assert that all outputs have different names
          assert len(set([s.name for s in func_output])) == len(
              func_output
          )
          assert all(
              [
                  isinstance(s.index, pd.DatetimeIndex)
                  for s in func_output
              ]
          )
          return {s.name: s for s in func_output}
  
      else:
          raise TypeError(
              f"Function output type is invalid for processor {func_name}"
          )
  
file_path: tsflex/tsflex/processing/series_processor.py
imports: import time
  from typing import Callable, Dict, List, Tuple, Union
  import numpy
  import pandas
  from ..None import __pdoc__
  from ..utils.classes import FrozenClass
  from ..utils.data import flatten, series_dict_to_df, to_list, to_tuple
  from .logger import logger
label_desc: Use image node_id 3 for calling a global function with example usage: _handle_seriesprocessor_func_output(func_output, required_dict, func_name) and returns: func_output, dict, dict, unknown