code: def get_window(obj, window_length=None, lag=None):
      """Slice obj to the time index window with given length and lag.
  
      Returns time series or time series panel with time indices
          strictly greater than cutoff - lag - window_length, and
          equal or less than cutoff - lag.
      Cutoff if of obj, as determined by get_cutoff.
  
      Parameters
      ----------
      obj : sktime compatible time series data container or None
          if not None, must be of Series, Panel, or Hierarchical scitype
          all mtypes are supported via conversion to internally supported types
          to avoid conversions, pass data in one of GET_WINDOW_SUPPORTED_MTYPES
      window_length : int or timedelta, optional, default=-inf
          must be int if obj is int indexed, timedelta if datetime indexed
          length of the window to slice to. Default = window of infinite size
      lag : int, timedelta, or None optional, default = None (zero of correct type)
          lag of the latest time in the window, with respect to cutoff of obj
          if None, is internally replaced by a zero of type compatible with obj index
          must be int if obj is int indexed or not pandas based
          must be timedelta if obj is pandas based and datetime indexed
  
      Returns
      -------
      obj sub-set to time indices in the semi-open interval
          (cutoff - window_length - lag, cutoff - lag)
          None if obj was None
      """
      from sktime.datatypes import check_is_scitype, convert_to
  
      if obj is None or (window_length is None and lag is None):
          return obj
  
      valid, _, metadata = check_is_scitype(
          obj,
          scitype=["Series", "Panel", "Hierarchical"],
          return_metadata=True,
      )
      if not valid:
          raise ValueError(
              "obj must be of Series, Panel, or Hierarchical scitype"
          )
      obj_in_mtype = metadata["mtype"]
  
      obj = convert_to(obj, GET_WINDOW_SUPPORTED_MTYPES)
  
      # numpy3D (Panel) or np.npdarray (Series)
      if isinstance(obj, np.ndarray):
          # if 2D or 3D, we need to subset by last, not first dimension
          # if 1D, we need to subset by first dimension
          # to achieve that effect, we swap first and last in case of 2D, 3D
          # and always subset on first dimension
          if obj.ndim > 1:
              obj = obj.swapaxes(1, -1)
          obj_len = len(obj)
          if lag is None:
              lag = 0
          if window_length is None:
              window_length = obj_len
          window_start = max(-window_length - lag, -obj_len)
          window_end = max(-lag, -obj_len)
          # we need to swap first and last dimension back before returning, if done above
          if window_end == 0:
              obj_subset = obj[window_start:]
          else:
              obj_subset = obj[window_start:window_end]
          if obj.ndim > 1:
              obj_subset = obj_subset.swapaxes(1, -1)
          return obj_subset
  
      # pd.DataFrame(Series), pd-multiindex (Panel) and pd_multiindex_hier (Hierarchical)
      if isinstance(obj, pd.DataFrame):
          cutoff = get_cutoff(obj)
  
          if not isinstance(obj.index, pd.MultiIndex):
              time_indices = obj.index
          else:
              time_indices = obj.index.get_level_values(-1)
  
          if lag is None:
              win_end_incl = cutoff
              win_select = time_indices <= win_end_incl
              if window_length is not None:
                  win_start_excl = cutoff - window_length
                  win_select = win_select & (
                      time_indices > win_start_excl
                  )
          else:
              win_end_incl = cutoff - lag
              win_select = time_indices <= win_end_incl
              if window_length is not None:
                  win_start_excl = cutoff - window_length - lag
                  win_select = win_select & (
                      time_indices > win_start_excl
                  )
  
          obj_subset = obj.iloc[win_select]
  
          return convert_to(obj_subset, obj_in_mtype)
  
      raise ValueError(
          "bug in get_window, unreachable condition, ifs should be exhaustive"
      )
  
file_path: sktime/sktime/datatypes/_utilities.py
imports: import numpy
  import pandas
label_desc: Use image node_id 7 for calling a global function with example usage: get_window(obj, window_length, lag) and returns: obj, obj_subset, convert_to