code: def roll_series_with_gap(
      series: Series,
      window_length: Union[int, str],
      gap: Union[int, str],
      min_periods: int,
  ) -> Rolling:
      """Provide rolling window calculations where the windows are determined using both a gap parameter
      that indicates the amount of time between each instance and its window and a window length parameter
      that determines the amount of data in each window.
  
      Args:
          series (Series): The series over which rolling windows will be created. The series must have numeric values and a DatetimeIndex.
          window_length (int, string): Specifies the amount of data included in each window.
              If an integer is provided, it will correspond to a number of rows. For data with a uniform sampling frequency,
              for example of one day, the window_length will correspond to a period of time, in this case,
              7 days for a window_length of 7.
              If a string is provided, it must be one of pandas' offset alias strings ('1D', '1H', etc),
              and it will indicate a length of time that each window should span.
              The list of available offset aliases can be found at
              https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
          gap (int, string, optional): Specifies a gap backwards from each instance before the
              window of usable data begins. If an integer is provided, it will correspond to a number of rows.
              If a string is provided, it must be one of pandas' offset alias strings ('1D', '1H', etc),
              and it will indicate a length of time between a target instance and the beginning of its window.
              Defaults to 0, which will include the target instance in the window.
          min_periods (int, optional): Minimum number of observations required for performing calculations
              over the window. Can only be as large as window_length when window_length is an integer.
              When window_length is an offset alias string, this limitation does not exist, but care should be taken
              to not choose a min_periods that will always be larger than the number of observations in a window.
              Defaults to 1.
  
      Returns:
          pandas.core.window.rolling.Rolling: The Rolling object for the series passed in.
      """
      _check_window_length(window_length)
      _check_gap(window_length, gap)
  
      functional_window_length = window_length
      if isinstance(gap, str):
          # Add the window_length and gap so that the rolling operation correctly takes gap into account.
          # That way, we can later remove the gap rows in order to apply the primitive function
          # to the correct window
          functional_window_length = to_offset(
              window_length
          ) + to_offset(gap)
      elif gap > 0:
          # When gap is numeric, we can apply a shift to incorporate gap right now
          # since the gap will be the same number of rows for the whole dataset
          series = series.shift(gap)
  
      return series.rolling(functional_window_length, min_periods)
  
file_path: featuretools/featuretools/primitives/standard/transform/time_series/utils.py
imports: from typing import Callable, Optional, Union
  import numpy
  import pandas
  from pandas import Series
  from pandas.core.window.rolling import Rolling
  from pandas.tseries.frequencies import to_offset
label_desc: Use image node_id 1 for calling a global function with example usage: roll_series_with_gap(series, window_length, gap, min_periods) and returns: series