pandas.api.indexers.BaseIndexer#

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

Base class for window bounds calculations.

Examples

>>> from pandas.api.indexers import BaseIndexer
>>> class CustomIndexer(BaseIndexer):
...     def get_window_bounds(self, num_values, min_periods, center, closed, step):
...         start = np.empty(num_values, dtype=np.int64)
...         end = np.empty(num_values, dtype=np.int64)
...         for i in range(num_values):
...             start[i] = i
...             end[i] = i + 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.