code: def _max_pooling(series: TimeSeries, window: int) -> TimeSeries:
      """Slides a window of size `window` along the input series, and replaces the value of the
      input time series by the maximum of the values contained in the window.
  
      The binary time series output represents if there is an anomaly (=1) or not (=0) in the past
      window points. The new series will equal the length of the input series - window. Its first
      point will start at the first time index of the input time series + window points.
  
      Parameters
      ----------
      series:
          Binary time series.
      window:
          Integer value indicating the number of past samples each point represents.
  
      Returns
      -------
      Binary TimeSeries
      """
  
      raise_if_not(
          isinstance(window, int),
          f"Parameter `window` must be of type int, found {type(window)}.",
      )
  
      raise_if_not(
          window > 0,
          f"Parameter `window` must be stricly greater than 0, found size {window}.",
      )
  
      raise_if_not(
          window < len(series),
          "Parameter `window` must be smaller than the length of the input series, "
          + f" found window size {(window)}, and max size {len(series)}.",
      )
  
      if window == 1:
          # the process results in replacing every value by itself -> return directly the series
          return series
      else:
          return series.window_transform(
              transforms={
                  "window": window,
                  "function": "max",
                  "mode": "rolling",
                  "min_periods": window,
              },
              treat_na="dropna",
          )
  
file_path: darts/darts/ad/utils.py
imports: from typing import Sequence, Tuple, Union
  import matplotlib.pyplot
  import numpy
  from sklearn.metrics import accuracy_score, average_precision_score, f1_score, precision_score, recall_score, roc_auc_score
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if, raise_if_not
label_desc: Use image node_id 8 for calling a global function with example usage: _max_pooling(series, window) and returns: series, series