Window Operations
The `window-ops` library provides optimized implementations of window operations such as rolling and expanding functions. It aims to offer a significant speedup over `pandas.Series.rolling` and `pandas.Series.expanding` by utilizing Numba-optimized functions that operate on NumPy arrays. The library also includes 'online' classes for efficiently updating window statistics as new data arrives. It is currently in an alpha development stage (0.0.15), with releases as features are added or improved.
Warnings
- gotcha The library primarily operates on NumPy arrays. If you are working with pandas Series or DataFrames, you will need to convert your data to NumPy arrays before using `window-ops` functions and potentially convert back to pandas if needed. This is different from `pd.Series.rolling` and `pd.Series.expanding` which work directly on Series.
- breaking This library is currently in 'Development Status :: 3 - Alpha'. This means the API is not yet stable and might introduce breaking changes between minor or patch versions (e.g., 0.0.x to 0.0.y) without following strict semantic versioning, although recent changes have been additive.
- gotcha Functions like `rolling_mean` and `expanding_mean` (and other statistics) are imported directly from submodules like `window_ops.rolling` and `window_ops.expanding`, not from the top-level `window_ops` package.
Install
-
pip install window-ops
Imports
- rolling_mean
from window_ops.rolling import rolling_mean
- expanding_mean
from window_ops.expanding import expanding_mean
- online
from window_ops import online
Quickstart
import numpy as np
from window_ops.rolling import rolling_mean
from window_ops.expanding import expanding_mean
data = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
# Calculate rolling mean with a window size of 3
rolling_result = rolling_mean(data, window_size=3)
print(f"Original data: {data}")
print(f"Rolling mean (window=3): {rolling_result}")
# Calculate expanding mean
expanding_result = expanding_mean(data)
print(f"Expanding mean: {expanding_result}")