window-ops


Namewindow-ops JSON
Version 0.0.14 PyPI version JSON
download
home_pagehttps://github.com/jmoralez/window_ops/tree/master/
SummaryImplementations of window operations such as rolling and expanding.
upload_time2023-03-22 03:34:43
maintainer
docs_urlNone
authorJosé Morales
requires_python>=3.6
licenseApache Software License 2.0
keywords rolling expanding
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Window ops
================

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

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

``` python
pd.__version__
```

    '1.3.5'

``` python
n_samples = 10_000  # array size
window_size = 8  # for rolling operations
season_length = 7  # for seasonal operations
execute_times = 10 # number of times each function will be executed
```

Average times in milliseconds.

``` python
times.applymap('{:.2f}'.format)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>window_ops</th>
      <th>pandas</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>rolling_mean</th>
      <td>0.03</td>
      <td>0.43</td>
    </tr>
    <tr>
      <th>rolling_max</th>
      <td>0.14</td>
      <td>0.57</td>
    </tr>
    <tr>
      <th>rolling_min</th>
      <td>0.14</td>
      <td>0.58</td>
    </tr>
    <tr>
      <th>rolling_std</th>
      <td>0.06</td>
      <td>0.54</td>
    </tr>
    <tr>
      <th>expanding_mean</th>
      <td>0.03</td>
      <td>0.31</td>
    </tr>
    <tr>
      <th>expanding_max</th>
      <td>0.05</td>
      <td>0.76</td>
    </tr>
    <tr>
      <th>expanding_min</th>
      <td>0.05</td>
      <td>0.47</td>
    </tr>
    <tr>
      <th>expanding_std</th>
      <td>0.09</td>
      <td>0.41</td>
    </tr>
    <tr>
      <th>seasonal_rolling_mean</th>
      <td>0.05</td>
      <td>3.89</td>
    </tr>
    <tr>
      <th>seasonal_rolling_max</th>
      <td>0.18</td>
      <td>4.27</td>
    </tr>
    <tr>
      <th>seasonal_rolling_min</th>
      <td>0.18</td>
      <td>3.75</td>
    </tr>
    <tr>
      <th>seasonal_rolling_std</th>
      <td>0.08</td>
      <td>4.38</td>
    </tr>
    <tr>
      <th>seasonal_expanding_mean</th>
      <td>0.04</td>
      <td>3.18</td>
    </tr>
    <tr>
      <th>seasonal_expanding_max</th>
      <td>0.06</td>
      <td>3.29</td>
    </tr>
    <tr>
      <th>seasonal_expanding_min</th>
      <td>0.06</td>
      <td>3.28</td>
    </tr>
    <tr>
      <th>seasonal_expanding_std</th>
      <td>0.12</td>
      <td>3.89</td>
    </tr>
  </tbody>
</table>
</div>

``` python
speedups = times['pandas'] / times['window_ops']
speedups = speedups.to_frame('times faster')
speedups.applymap('{:.0f}'.format)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>times faster</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>rolling_mean</th>
      <td>15</td>
    </tr>
    <tr>
      <th>rolling_max</th>
      <td>4</td>
    </tr>
    <tr>
      <th>rolling_min</th>
      <td>4</td>
    </tr>
    <tr>
      <th>rolling_std</th>
      <td>9</td>
    </tr>
    <tr>
      <th>expanding_mean</th>
      <td>12</td>
    </tr>
    <tr>
      <th>expanding_max</th>
      <td>15</td>
    </tr>
    <tr>
      <th>expanding_min</th>
      <td>9</td>
    </tr>
    <tr>
      <th>expanding_std</th>
      <td>4</td>
    </tr>
    <tr>
      <th>seasonal_rolling_mean</th>
      <td>77</td>
    </tr>
    <tr>
      <th>seasonal_rolling_max</th>
      <td>23</td>
    </tr>
    <tr>
      <th>seasonal_rolling_min</th>
      <td>21</td>
    </tr>
    <tr>
      <th>seasonal_rolling_std</th>
      <td>52</td>
    </tr>
    <tr>
      <th>seasonal_expanding_mean</th>
      <td>78</td>
    </tr>
    <tr>
      <th>seasonal_expanding_max</th>
      <td>52</td>
    </tr>
    <tr>
      <th>seasonal_expanding_min</th>
      <td>51</td>
    </tr>
    <tr>
      <th>seasonal_expanding_std</th>
      <td>33</td>
    </tr>
  </tbody>
</table>
</div>

### 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.

``` python
times.to_frame().applymap('{:.2f}'.format)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>average time (ms)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>RollingMean</th>
      <td>0.12</td>
    </tr>
    <tr>
      <th>RollingMax</th>
      <td>0.23</td>
    </tr>
    <tr>
      <th>RollingMin</th>
      <td>0.22</td>
    </tr>
    <tr>
      <th>RollingStd</th>
      <td>0.32</td>
    </tr>
    <tr>
      <th>ExpandingMean</th>
      <td>0.10</td>
    </tr>
    <tr>
      <th>ExpandingMax</th>
      <td>0.07</td>
    </tr>
    <tr>
      <th>ExpandingMin</th>
      <td>0.07</td>
    </tr>
    <tr>
      <th>ExpandingStd</th>
      <td>0.17</td>
    </tr>
    <tr>
      <th>SeasonalRollingMean</th>
      <td>0.28</td>
    </tr>
    <tr>
      <th>SeasonalRollingMax</th>
      <td>0.35</td>
    </tr>
    <tr>
      <th>SeasonalRollingMin</th>
      <td>0.38</td>
    </tr>
    <tr>
      <th>SeasonalRollingStd</th>
      <td>0.42</td>
    </tr>
    <tr>
      <th>SeasonalExpandingMean</th>
      <td>0.17</td>
    </tr>
    <tr>
      <th>SeasonalExpandingMax</th>
      <td>0.14</td>
    </tr>
    <tr>
      <th>SeasonalExpandingMin</th>
      <td>0.15</td>
    </tr>
    <tr>
      <th>SeasonalExpandingStd</th>
      <td>0.23</td>
    </tr>
  </tbody>
</table>
</div>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jmoralez/window_ops/tree/master/",
    "name": "window-ops",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "rolling,expanding",
    "author": "Jos\u00e9 Morales",
    "author_email": "jmorales@grupoabraxas.com",
    "download_url": "https://files.pythonhosted.org/packages/41/9f/7a223bc743bd25d59f7865104ccc0c75073afe0c6d3ab8c20d1f37e9c1c5/window_ops-0.0.14.tar.gz",
    "platform": null,
    "description": "Window ops\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nThis library is intended to be used as an alternative to\n`pd.Series.rolling` and `pd.Series.expanding` to gain a speedup by using\nnumba optimized functions operating on numpy arrays. There are also\nonline classes for more efficient updates of window statistics.\n\n## Install\n\n`pip install window-ops`\n\n## How to use\n\n### Transformations\n\nFor a transformations `n_samples` -\\> `n_samples` you can use\n`{[seasonal_](rolling|expanding)}_{(mean|max|min|std)}` on an array.\n\n#### Benchmarks\n\n``` python\npd.__version__\n```\n\n    '1.3.5'\n\n``` python\nn_samples = 10_000  # array size\nwindow_size = 8  # for rolling operations\nseason_length = 7  # for seasonal operations\nexecute_times = 10 # number of times each function will be executed\n```\n\nAverage times in milliseconds.\n\n``` python\ntimes.applymap('{:.2f}'.format)\n```\n\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>window_ops</th>\n      <th>pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>rolling_mean</th>\n      <td>0.03</td>\n      <td>0.43</td>\n    </tr>\n    <tr>\n      <th>rolling_max</th>\n      <td>0.14</td>\n      <td>0.57</td>\n    </tr>\n    <tr>\n      <th>rolling_min</th>\n      <td>0.14</td>\n      <td>0.58</td>\n    </tr>\n    <tr>\n      <th>rolling_std</th>\n      <td>0.06</td>\n      <td>0.54</td>\n    </tr>\n    <tr>\n      <th>expanding_mean</th>\n      <td>0.03</td>\n      <td>0.31</td>\n    </tr>\n    <tr>\n      <th>expanding_max</th>\n      <td>0.05</td>\n      <td>0.76</td>\n    </tr>\n    <tr>\n      <th>expanding_min</th>\n      <td>0.05</td>\n      <td>0.47</td>\n    </tr>\n    <tr>\n      <th>expanding_std</th>\n      <td>0.09</td>\n      <td>0.41</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_mean</th>\n      <td>0.05</td>\n      <td>3.89</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_max</th>\n      <td>0.18</td>\n      <td>4.27</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_min</th>\n      <td>0.18</td>\n      <td>3.75</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_std</th>\n      <td>0.08</td>\n      <td>4.38</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_mean</th>\n      <td>0.04</td>\n      <td>3.18</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_max</th>\n      <td>0.06</td>\n      <td>3.29</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_min</th>\n      <td>0.06</td>\n      <td>3.28</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_std</th>\n      <td>0.12</td>\n      <td>3.89</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n``` python\nspeedups = times['pandas'] / times['window_ops']\nspeedups = speedups.to_frame('times faster')\nspeedups.applymap('{:.0f}'.format)\n```\n\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>times faster</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>rolling_mean</th>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>rolling_max</th>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>rolling_min</th>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>rolling_std</th>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>expanding_mean</th>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>expanding_max</th>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>expanding_min</th>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>expanding_std</th>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_mean</th>\n      <td>77</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_max</th>\n      <td>23</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_min</th>\n      <td>21</td>\n    </tr>\n    <tr>\n      <th>seasonal_rolling_std</th>\n      <td>52</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_mean</th>\n      <td>78</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_max</th>\n      <td>52</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_min</th>\n      <td>51</td>\n    </tr>\n    <tr>\n      <th>seasonal_expanding_std</th>\n      <td>33</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n### Online\n\nIf you have an array for which you want to compute a window statistic\nand then keep updating it as more samples come in you can use the\nclasses in the `window_ops.online` module. They all have a\n`fit_transform` method which take the array and return the\ntransformations defined above but also have an `update` method that take\na single value and return the new statistic.\n\n#### Benchmarks\n\nAverage time in milliseconds it takes to transform the array and perform\n100 updates.\n\n``` python\ntimes.to_frame().applymap('{:.2f}'.format)\n```\n\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>average time (ms)</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>RollingMean</th>\n      <td>0.12</td>\n    </tr>\n    <tr>\n      <th>RollingMax</th>\n      <td>0.23</td>\n    </tr>\n    <tr>\n      <th>RollingMin</th>\n      <td>0.22</td>\n    </tr>\n    <tr>\n      <th>RollingStd</th>\n      <td>0.32</td>\n    </tr>\n    <tr>\n      <th>ExpandingMean</th>\n      <td>0.10</td>\n    </tr>\n    <tr>\n      <th>ExpandingMax</th>\n      <td>0.07</td>\n    </tr>\n    <tr>\n      <th>ExpandingMin</th>\n      <td>0.07</td>\n    </tr>\n    <tr>\n      <th>ExpandingStd</th>\n      <td>0.17</td>\n    </tr>\n    <tr>\n      <th>SeasonalRollingMean</th>\n      <td>0.28</td>\n    </tr>\n    <tr>\n      <th>SeasonalRollingMax</th>\n      <td>0.35</td>\n    </tr>\n    <tr>\n      <th>SeasonalRollingMin</th>\n      <td>0.38</td>\n    </tr>\n    <tr>\n      <th>SeasonalRollingStd</th>\n      <td>0.42</td>\n    </tr>\n    <tr>\n      <th>SeasonalExpandingMean</th>\n      <td>0.17</td>\n    </tr>\n    <tr>\n      <th>SeasonalExpandingMax</th>\n      <td>0.14</td>\n    </tr>\n    <tr>\n      <th>SeasonalExpandingMin</th>\n      <td>0.15</td>\n    </tr>\n    <tr>\n      <th>SeasonalExpandingStd</th>\n      <td>0.23</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "Implementations of window operations such as rolling and expanding.",
    "version": "0.0.14",
    "split_keywords": [
        "rolling",
        "expanding"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b03c7a1c3f677917bce66713069dd78e2159b61e84c184b8afcc6e9ea7161a56",
                "md5": "df6f57c58cd540142ff03a32097a0692",
                "sha256": "d85dc6a9cfcfd61bfae798c057ea354045218cfb0eebdf38d0dd7799ac762086"
            },
            "downloads": -1,
            "filename": "window_ops-0.0.14-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "df6f57c58cd540142ff03a32097a0692",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 14874,
            "upload_time": "2023-03-22T03:34:41",
            "upload_time_iso_8601": "2023-03-22T03:34:41.862704Z",
            "url": "https://files.pythonhosted.org/packages/b0/3c/7a1c3f677917bce66713069dd78e2159b61e84c184b8afcc6e9ea7161a56/window_ops-0.0.14-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "419f7a223bc743bd25d59f7865104ccc0c75073afe0c6d3ab8c20d1f37e9c1c5",
                "md5": "3dcf4bdea2b9f6650237d7e01641cb2f",
                "sha256": "4c0d4686c50ba1fc1de7d41da706b57118d8fb45531e5a23f06104f804788c1d"
            },
            "downloads": -1,
            "filename": "window_ops-0.0.14.tar.gz",
            "has_sig": false,
            "md5_digest": "3dcf4bdea2b9f6650237d7e01641cb2f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 15652,
            "upload_time": "2023-03-22T03:34:43",
            "upload_time_iso_8601": "2023-03-22T03:34:43.568618Z",
            "url": "https://files.pythonhosted.org/packages/41/9f/7a223bc743bd25d59f7865104ccc0c75073afe0c6d3ab8c20d1f37e9c1c5/window_ops-0.0.14.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-22 03:34:43",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "window-ops"
}
        
Elapsed time: 0.04832s