code: def _hampel_filter(Z, cv, n_sigma, half_window_length, k):
      for i in cv.split(Z):
          cv_window = i[0]
          cv_median = np.nanmedian(Z[cv_window])
          cv_sigma = k * np.nanmedian(
              np.abs(Z.iloc[cv_window] - cv_median)
          )
  
          is_start_window = cv_window[-1] == cv.window_length - 1
          is_end_window = cv_window[-1] == len(Z) - 1
          if is_start_window:
              idx_range = range(cv_window[0], half_window_length + 1)
          elif is_end_window:
              if cv.window_length % 2 == 0:
                  start_end_win = half_window_length
              else:
                  start_end_win = ceil(cv.window_length / 2)
              idx_range = range(len(Z) - start_end_win, len(Z))
          else:
              idx_range = [cv_window[0] + half_window_length]
  
          for idx in idx_range:
              Z.iloc[idx] = _compare(
                  value=Z.iloc[idx],
                  cv_median=cv_median,
                  cv_sigma=cv_sigma,
                  n_sigma=n_sigma,
              )
      return Z
  
file_path: sktime/sktime/transformations/series/outlier_detection.py
imports: import warnings
  from math import ceil
  import numpy
  import pandas
  from sktime.split import SlidingWindowSplitter
  from sktime.transformations.base import BaseTransformer
label_desc: Use image node_id 1 for calling a global function with example usage: _hampel_filter(Z, cv, n_sigma, half_window_length, k) and returns: Z