Skip to main content

Implementations of window operations such as rolling and expanding.

Project description

Window ops

Naive and fast implementations of common window operations.

This library is intended to be used as an alternative to pd.Series.rolling and pd.Series.expanding to gain a speedup by using numba optimized functions operating on numpy arrays. There are also online classes for more efficient updates of window statistics.

Install

pip install window-ops

How to use

Transformations

For a transformations n_samples -> n_samples you can use {[seasonal_](rolling|expanding)}_{(mean|max|min|std)} on an array.

Benchmarks

pd.__version__
'1.2.3'
n_samples = 1_000  # array size
window_size = 8  # for rolling operations
season_length = 7  # for seasonal operations
execute_times = 1_000 # number of times each function will be executed

Average times in milliseconds.

display_dataframe(times, fmt='{:.2f}')
window_ops pandas
rolling_mean 0 0.17
rolling_max 0.01 0.19
rolling_min 0.01 0.23
rolling_std 0.01 0.22
expanding_mean 0 0.13
expanding_max 0 0.13
expanding_min 0 0.13
expanding_std 0.01 0.14
seasonal_rolling_mean 0 2.62
seasonal_rolling_max 0.02 3.04
seasonal_rolling_min 0.02 2.85
seasonal_rolling_std 0.01 2.37
seasonal_expanding_mean 0 1.9
seasonal_expanding_max 0.01 1.79
seasonal_expanding_min 0.01 1.81
seasonal_expanding_std 0.01 2.45
display_dataframe(speedups, fmt='{:.0f}')
times faster
rolling_mean 76
rolling_max 14
rolling_min 21
rolling_std 33
expanding_mean 44
expanding_max 32
expanding_min 32
expanding_std 19
seasonal_rolling_mean 632
seasonal_rolling_max 201
seasonal_rolling_min 173
seasonal_rolling_std 322
seasonal_expanding_mean 494
seasonal_expanding_max 353
seasonal_expanding_min 339
seasonal_expanding_std 238

Online

If you have an array for which you want to compute a window statistic and then keep updating it as more samples come in you can use the classes in the window_ops.online module. They all have a fit_transform method which take the array and return the transformations defined above but also have an update method that take a single value and return the new statistic.

Benchmarks

Average time in milliseconds it takes to transform the array and perform 100 updates.

display_dataframe(times.to_frame(), '{:.2f}')
average time (ms)
RollingMean 0.07
RollingMax 0.09
RollingMin 0.09
RollingStd 0.24
ExpandingMean 0.08
ExpandingMax 0.03
ExpandingMin 0.02
ExpandingStd 0.08
SeasonalRollingMean 0.18
SeasonalRollingMax 0.14
SeasonalRollingMin 0.19
SeasonalRollingStd 0.25
SeasonalExpandingMean 0.09
SeasonalExpandingMax 0.06
SeasonalExpandingMin 0.06
SeasonalExpandingStd 0.09

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

window_ops-0.0.13.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

window_ops-0.0.13-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file window_ops-0.0.13.tar.gz.

File metadata

  • Download URL: window_ops-0.0.13.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for window_ops-0.0.13.tar.gz
Algorithm Hash digest
SHA256 a86adaeb73e67b2924129cde9bc649227d37333bd506c876c9623d764d5c6f76
MD5 d1e840617d166f126114877a7fe97fc4
BLAKE2b-256 51674ab1e3dbff3fd92fa18911afe91a9124281820eb1145b5669fbd25fe787c

See more details on using hashes here.

File details

Details for the file window_ops-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: window_ops-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for window_ops-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 27a2cf82983f645f6101cf85739debe42fcf2d7b25cbc7766d4084462a56a52e
MD5 ab6d97c663f047eb385ca4892372a90f
BLAKE2b-256 8fe9a0a4386689338afea5b6b26c296aac2dc60ceb19009c3eecf5cd5f475368

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page