Skip to main content
`Ctrl`+`K`

# pandas.api.indexers.BaseIndexer

class pandas.api.indexers.BaseIndexer(index_array=None, window_size=0, **kwargs)

  Base class for window bounds calculations.

  Parameters:
    index_array np.ndarray, default None

      Array-like structure representing the indices for the data points. If None, the default indices are assumed. This can be useful for handling non-uniform indices in data, such as in time series with irregular timestamps.

    window_size int, default 0

      Size of the moving window. This is the number of observations used for calculating the statistic. The default is to consider all observations within the window.

    **kwargs

      Additional keyword arguments passed to the subclass’s methods.

  See also

  `DataFrame.rolling`

    Provides rolling window calculations on dataframe.

  `Series.rolling`

    Provides rolling window calculations on series.

  Examples

      >>> from pandas.api.indexers import BaseIndexer
      >>> class CustomIndexer(BaseIndexer):
      ...     def get_window_bounds(self, num_values, min_periods, center, closed, step):
      ...         start = np.arange(num_values, dtype=np.int64)
      ...         end = np.arange(num_values, dtype=np.int64) + self.window_size
      ...         return start, end
      >>> df = pd.DataFrame({"values": range(5)})
      >>> indexer = CustomIndexer(window_size=2)
      >>> df.rolling(indexer).sum()
          values
      0   1.0
      1   3.0
      2   5.0
      3   7.0
      4   4.0

  Methods

  `get_window_bounds`([num_values, min_periods, ...]) | Computes the bounds of a window.