Skip to content

DOC: Add example of NonFixedVariableWindowIndexer usage #34994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/source/user_guide/computation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,18 @@ You can view other examples of ``BaseIndexer`` subclasses `here <https://github.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show df here

.. versionadded:: 1.1

One subclass of note within those examples is the ``NonFixedVariableWindowIndexer`` that allows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rename this Indexer, its a bit redundant (NonFixedVariable)......followon ok

rolling operations over a non-fixed offset like a ``BusinessDay``.

.. ipython:: python

from pandas.api.indexers import NonFixedVariableWindowIndexer
df = pd.DataFrame(range(10), index=pd.date_range('2020', periods=10))
offset = pd.offsets.BDay(1)
indexer = NonFixedVariableWindowIndexer(index=df.index, offset=offset)
df
df.rolling(indexer).sum()

For some problems knowledge of the future is available for analysis. For example, this occurs when
each data point is a full time series read from an experiment, and the task is to extract underlying
conditions. In these cases it can be useful to perform forward-looking rolling window computations.
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ Other API changes
- ``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`)
- 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`)
- Added a :func:`pandas.api.indexers.FixedForwardWindowIndexer` class to support forward-looking windows during ``rolling`` operations.
- Added a :func:`pandas.api.indexers.NonFixedVariableWindowIndexer` class to support ``rolling`` operations with non-fixed offsets (:issue:`34994`)
- Added :class:`pandas.errors.InvalidIndexError` (:issue:`34570`).
- :meth:`DataFrame.swaplevels` now raises a ``TypeError`` if the axis is not a :class:`MultiIndex`.
Previously an ``AttributeError`` was raised (:issue:`31126`)
Expand Down
13 changes: 11 additions & 2 deletions pandas/api/indexers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
"""

from pandas.core.indexers import check_array_indexer
from pandas.core.window.indexers import BaseIndexer, FixedForwardWindowIndexer
from pandas.core.window.indexers import (
BaseIndexer,
FixedForwardWindowIndexer,
NonFixedVariableWindowIndexer,
)

__all__ = ["check_array_indexer", "BaseIndexer", "FixedForwardWindowIndexer"]
__all__ = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test for this in test_api (followon ok)

"check_array_indexer",
"BaseIndexer",
"FixedForwardWindowIndexer",
"NonFixedVariableWindowIndexer",
]