Skip to content

Commit bce11e2

Browse files
authored
DOC: Add example of NonFixedVariableWindowIndexer usage (#34994)
1 parent 549b0ff commit bce11e2

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

doc/source/user_guide/computation.rst

+12
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,18 @@ You can view other examples of ``BaseIndexer`` subclasses `here <https://github.
597597

598598
.. versionadded:: 1.1
599599

600+
One subclass of note within those examples is the ``NonFixedVariableWindowIndexer`` that allows
601+
rolling operations over a non-fixed offset like a ``BusinessDay``.
602+
603+
.. ipython:: python
604+
605+
from pandas.api.indexers import NonFixedVariableWindowIndexer
606+
df = pd.DataFrame(range(10), index=pd.date_range('2020', periods=10))
607+
offset = pd.offsets.BDay(1)
608+
indexer = NonFixedVariableWindowIndexer(index=df.index, offset=offset)
609+
df
610+
df.rolling(indexer).sum()
611+
600612
For some problems knowledge of the future is available for analysis. For example, this occurs when
601613
each data point is a full time series read from an experiment, and the task is to extract underlying
602614
conditions. In these cases it can be useful to perform forward-looking rolling window computations.

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ Other API changes
673673
- ``loc`` lookups with an object-dtype :class:`Index` and an integer key will now raise ``KeyError`` instead of ``TypeError`` when key is missing (:issue:`31905`)
674674
- Using a :func:`pandas.api.indexers.BaseIndexer` with ``count``, ``min``, ``max``, ``median``, ``skew``, ``cov``, ``corr`` will now return correct results for any monotonic :func:`pandas.api.indexers.BaseIndexer` descendant (:issue:`32865`)
675675
- Added a :func:`pandas.api.indexers.FixedForwardWindowIndexer` class to support forward-looking windows during ``rolling`` operations.
676+
- Added a :func:`pandas.api.indexers.NonFixedVariableWindowIndexer` class to support ``rolling`` operations with non-fixed offsets (:issue:`34994`)
676677
- Added :class:`pandas.errors.InvalidIndexError` (:issue:`34570`).
677678
- :meth:`DataFrame.swaplevels` now raises a ``TypeError`` if the axis is not a :class:`MultiIndex`.
678679
Previously an ``AttributeError`` was raised (:issue:`31126`)

pandas/api/indexers/__init__.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
"""
44

55
from pandas.core.indexers import check_array_indexer
6-
from pandas.core.window.indexers import BaseIndexer, FixedForwardWindowIndexer
6+
from pandas.core.window.indexers import (
7+
BaseIndexer,
8+
FixedForwardWindowIndexer,
9+
NonFixedVariableWindowIndexer,
10+
)
711

8-
__all__ = ["check_array_indexer", "BaseIndexer", "FixedForwardWindowIndexer"]
12+
__all__ = [
13+
"check_array_indexer",
14+
"BaseIndexer",
15+
"FixedForwardWindowIndexer",
16+
"NonFixedVariableWindowIndexer",
17+
]

0 commit comments

Comments
 (0)