code: def roll(*args, **kwargs):
      """
      Calculates a given statistic across a rolling time period.
  
      Parameters
      ----------
      returns : pd.Series or np.ndarray
          Daily returns of the strategy, noncumulative.
          - See full explanation in :func:`~empyrical.stats.cum_returns`.
      factor_returns (optional): float / series
          Benchmark return to compare returns against.
      function:
          the function to run for each rolling window.
      window (keyword): int
          the number of periods included in each calculation.
      (other keywords): other keywords that are required to be passed to the
          function in the 'function' argument may also be passed in.
  
      Returns
      -------
      np.ndarray, pd.Series
          depends on input type
          ndarray(s) ==> ndarray
          Series(s) ==> pd.Series
  
          A Series or ndarray of the results of the stat across the rolling
          window.
  
      """
      func = kwargs.pop("function")
      window = kwargs.pop("window")
      if len(args) > 2:
          raise ValueError("Cannot pass more than 2 return sets")
  
      if len(args) == 2:
          if not isinstance(args[0], type(args[1])):
              raise ValueError(
                  "The two returns arguments are not the same."
              )
  
      if isinstance(args[0], np.ndarray):
          return _roll_ndarray(func, window, *args, **kwargs)
      return _roll_pandas(func, window, *args, **kwargs)
  
imports: from datetime import datetime
  from functools import wraps
  from os import makedirs, environ
  from os.path import expanduser, join, getmtime, isdir
  import errno
  import warnings
  import numpy
  from numpy.lib.stride_tricks import as_strided
  import pandas
  from pandas.tseries.offsets import BDay
  from .deprecate import deprecated
label_desc: Use image node_id 1 for calling a global function with example usage: roll() and returns: _roll_pandas, _roll_ndarray