code: def _window_feature(Z, summarizer=None, window=None, bfill=False):
      """Compute window features and lag.
  
      Apply summarizer passed over a certain window
      of past observations, e.g. the mean of a window of length 7 days, lagged by 14 days.
  
      Z: pandas Dataframe with a single column.
      name : str, base string of the derived features, will be appended by
          `lag` and window length parameters defined in window.
      summarizer: either str corresponding to pandas window function, currently
              * "sum",
              * "mean",
              * "median",
              * "std",
              * "var",
              * "kurt",
              * "min",
              * "max",
              * "corr",
              * "cov",
              * "skew",
              * "sem"
           or custom function call. See for the native window functions also
           https://pandas.pydata.org/docs/reference/window.html.
      window: list of integers
          List containing window_length and lag parameters, see WindowSummarizer
          class description for in-depth explanation.
      """
      lag = window[0]
      window_length = window[1]
  
      if summarizer in pd_rolling:
          if isinstance(Z, pd.core.groupby.generic.SeriesGroupBy):
              if bfill is False:
                  feat = getattr(
                      Z.shift(lag).rolling(
                          window=window_length,
                          min_periods=window_length,
                      ),
                      summarizer,
                  )()
              else:
                  feat = getattr(
                      Z.shift(lag)
                      .bfill()
                      .rolling(
                          window=window_length,
                          min_periods=window_length,
                      ),
                      summarizer,
                  )()
              feat = pd.DataFrame(feat)
          else:
              if bfill is False:
                  feat = Z.apply(
                      lambda x: getattr(
                          x.shift(lag).rolling(
                              window=window_length,
                              min_periods=window_length,
                          ),
                          summarizer,
                      )()
                  )
              else:
                  feat = Z.apply(
                      lambda x: getattr(
                          x.shift(lag)
                          .bfill()
                          .rolling(
                              window=window_length,
                              min_periods=window_length,
                          ),
                          summarizer,
                      )()
                  )
      else:
          if bfill is False:
              feat = Z.shift(lag)
          else:
              feat = Z.shift(lag).bfill()
          if isinstance(
              Z, pd.core.groupby.generic.SeriesGroupBy
          ) and callable(summarizer):
              feat = feat.rolling(window_length).apply(
                  summarizer, raw=True
              )
          elif not isinstance(
              Z, pd.core.groupby.generic.SeriesGroupBy
          ) and callable(summarizer):
              feat = feat.apply(
                  lambda x: x.rolling(
                      window=window_length, min_periods=window_length
                  ).apply(summarizer, raw=True)
              )
          feat = pd.DataFrame(feat)
      if bfill is True:
          feat = feat.bfill()
  
      if callable(summarizer):
          name = summarizer.__name__
      else:
          name = summarizer
  
      if name == "lag":
          feat.rename(
              columns={feat.columns[0]: name + "_" + str(window[0])},
              inplace=True,
          )
      else:
          feat.rename(
              columns={
                  feat.columns[0]: name
                  + "_"
                  + "_".join([str(item) for item in window])
              },
              inplace=True,
          )
      return feat
  
imports: import pandas
  from joblib import Parallel, delayed
  from sktime.split import ExpandingWindowSplitter, SlidingWindowSplitter
  from sktime.transformations.base import BaseTransformer
  from sktime.utils.multiindex import flatten_multiindex
label_desc: Use image node_id 2 for calling a global function with example usage: _window_feature(Z, summarizer, window, bfill) and returns: feat