class_docstr: Format a time series dataframe or list of dataframes into the a format that matches the structure learned by
      `from_pandas_dynamic`. This is done to allow for bayesian network probability fitting.
  
      Example of utilisation:
      >>> ddt = DynamicDataTransformer(p=p).fit(time_series, return_df=False)
      >>> X, Xlags = ddt.transform(time_series)
  
      >>> ddt = DynamicDataTransformer(p=p).fit(time_series, return_df=True)
      >>> df = ddt.transform(time_series)
docstr: Applies transformation to format the dataframe properly
  Args:
      time_series: time_series: pd.DataFrame or List of pd.DataFrame instances. Details on `fit` documentation
  
  Returns:
      - If `self.return_df=True`, returns a pandas.DataFrame on the following format:
  
          A_lag0 B_lag0 C_lag0 ... A_lag1 B_lag1 C_lag1 ... A_lag`p` B_lag`p` C_lag`p`
              X     X      X          X     X      X          X        X        X
              X     X      X          X     X      X          X        X        X
              X     X      X          X     X      X          X        X        X
      `lag0` denotes the current variable state and lag`k` denotes the states `k` time stamps in the past.
  
      - If `self.return_df=False`, returns a tuple of two numpy.ndarrayy: X and Xlags
              X (np.ndarray): 2d input data, axis=1 is data columns, axis=0 is data rows.
                  Each column represents one variable,
                  and each row represents x(m,t) i.e. the mth time series at time t.
              Xlags (np.ndarray):
                  Shifted data of X with lag orders stacking horizontally. Xlags=[shift(X,1)|...|shift(X,p)]
  Raises:
      NotFittedError: if `transform` called before `fit`
docstr_tok: ["Applies","transformation","to","format","the","dataframe","properly","Args",":","time_series",":","time_series",":","pd.DataFrame","or","List","of","pd.DataFrame","instances",".","Details","on","`","fit","`","documentation","Returns",":","-","If","`","self.return_df=True","`",",","returns","a","pandas.DataFrame","on","the","following","format",":","A_lag0","B_lag0","C_lag0","...","A_lag1","B_lag1","C_lag1","...","A_lag","`","p","`","B_lag","`","p","`","C_lag","`","p","`","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","`","lag0","`","denotes","the","current","variable","state","and","lag","`","k","`","denotes","the","states","`","k","`","time","stamps","in","the","past",".","-","If","`","self.return_df=False","`",",","returns","a","tuple","of","two","numpy.ndarrayy",":","X","and","Xlags","X","(","np.ndarray",")",":","2d","input","data",",","axis=1","is","data","columns",",","axis=0","is","data","rows",".","Each","column","represents","one","variable",",","and","each","row","represents","x","(","m",",","t",")","i.e",".","the","mth","time","series","at","time","t.","Xlags","(","np.ndarray",")",":","Shifted","data","of","X","with","lag","orders","stacking","horizontally",".","Xlags=","[","shift","(","X,1",")","|","...","|shift","(","X",",","p",")","]","Raises",":","NotFittedError",":","if","`","transform","`","called","before","`","fit","`"]
code: def transform(
      self, time_series: Union[pd.DataFrame, List[pd.DataFrame]]
  ) -> Union[pd.DataFrame, Tuple[np.ndarray, np.ndarray]]:
      """
      Applies transformation to format the dataframe properly
      Args:
          time_series: time_series: pd.DataFrame or List of pd.DataFrame instances. Details on `fit` documentation
  
      Returns:
          - If `self.return_df=True`, returns a pandas.DataFrame on the following format:
  
              A_lag0 B_lag0 C_lag0 ... A_lag1 B_lag1 C_lag1 ... A_lag`p` B_lag`p` C_lag`p`
                  X     X      X          X     X      X          X        X        X
                  X     X      X          X     X      X          X        X        X
                  X     X      X          X     X      X          X        X        X
          `lag0` denotes the current variable state and lag`k` denotes the states `k` time stamps in the past.
  
          - If `self.return_df=False`, returns a tuple of two numpy.ndarrayy: X and Xlags
                  X (np.ndarray): 2d input data, axis=1 is data columns, axis=0 is data rows.
                      Each column represents one variable,
                      and each row represents x(m,t) i.e. the mth time series at time t.
                  Xlags (np.ndarray):
                      Shifted data of X with lag orders stacking horizontally. Xlags=[shift(X,1)|...|shift(X,p)]
      Raises:
          NotFittedError: if `transform` called before `fit`
      """
      if self.columns is None:
          raise NotFittedError(
              "This DynamicDataTransformer is not fitted yet. "
              "Call `fit` before using this method"
          )
  
      time_series = (
          time_series
          if isinstance(time_series, list)
          else [time_series]
      )
  
      self._check_input_from_pandas(time_series)
  
      time_series = [t[self.columns] for t in time_series]
      ts_realisations = self._cut_dataframes_on_discontinuity_points(
          time_series
      )
      X, Xlags = self._convert_realisations_into_dynotears_format(
          ts_realisations, self.p
      )
  
      if self.return_df:
          res = self._concat_lags(X, Xlags)
          return res
      return X, Xlags
  
file_path: causalnex/causalnex/structure/transformers.py
imports: from copy import deepcopy
  from typing import List, Tuple, Union
  import numpy
  import pandas
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.exceptions import NotFittedError
label_desc: Use image node_id 3 for calling the DynamicDataTransformer obj's underlying member method code with example usage: obj.transform(time_series) and returns: X,  Xlags, res