code: def apply_rolling_agg_to_series(
      series: Series,
      agg_func: Callable[[Series], float],
      window_length: Union[int, str],
      gap: Union[int, str] = 0,
      min_periods: int = 1,
      ignore_window_nans: bool = False,
  ) -> np.ndarray:
      """Applies a given aggregation function to a rolled series.
  
      Args:
          series (Series): The series over which rolling windows will be created. The series must have numeric values and a DatetimeIndex.
          agg_func (callable[Series -> float]): The aggregation function to apply to a rolled series.
          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.
          ignore_window_nans (bool, optional): Whether or not NaNs in the rolling window should be included in the rolling calculation.
              NaNs by default get counted towards min_periods. When set to True,
              all partial values calculated by `agg_func` in the rolling window get replaced with NaN.
              Defaults to False.
  
      Returns:
          numpy.ndarray: The array of rolling calculated values.
  
      Note:
          Certain operations, like `pandas.core.window.rolling.Rolling.count` that can be performed
          on the Rolling object returned here may treat NaNs as periods to include in window calculations.
          So a window [NaN, 1, 3]  when `min_periods=3` will proceed with count, saying there are three periods
          but only two values and would return count=2. The calculation `max` on the other hand,
          would not recognize NaN as a valid period, and would therefore return `max=NaN` as the window has
          less valid periods (two, in this case) than `min_periods` (three, in this case).
          Most rolling calculations act this way. The implication of that here is that in order to
          achieve the gap, we insert NaNs at the beginning of the series, which would cause `count` to calculate
          on windows that technically should not have the correct number of periods. Any primitive that uses this function
          should determine whether `ignore_window_nans` should be set to `true`.
  
      Note:
          Only offset aliases with fixed frequencies can be used when defining gap and window_length.
          This means that aliases such as `M` or `W` cannot be used, as they can indicate different
          numbers of days. ('M', because different months have different numbers of days;
          'W' because week will indicate a certain day of the week, like W-Wed, so that will
          indicate a different number of days depending on the anchoring date.)
  
      Note:
          When using an offset alias to define `gap`, an offset alias must also be used to define `window_length`.
          This limitation does not exist when using an offset alias to define `window_length`. In fact,
          if the data has a uniform sampling frequency, it is preferable to use a numeric `gap` as it is more
          efficient."""
      rolled_series = roll_series_with_gap(
          series, window_length, gap, min_periods
      )
      if isinstance(gap, str):
          additional_args = (gap, agg_func, min_periods)
          return rolled_series.apply(
              apply_roll_with_offset_gap,
              args=additional_args,
          ).values
      applied_rolled_series = rolled_series.apply(agg_func)
  
      if ignore_window_nans:
          if not min_periods:
              # when min periods is 0 or None it's treated the same as if it's 1
              num_nans = gap
          else:
              num_nans = min_periods - 1 + gap
          applied_rolled_series.iloc[range(num_nans)] = np.nan
      return applied_rolled_series.values
  
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 6 for calling a global function with example usage: apply_rolling_agg_to_series(series, agg_func, window_length, gap, min_periods, ignore_window_nans) and returns: applied_rolled_series, rolled_series