pd-window-decorators


Namepd-window-decorators JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryA decorator for applying a moving window to a function that consumes and returns a Pandas DataFrame.
upload_time2024-01-20 17:10:54
maintainer
docs_urlNone
author
requires_python>=3.9
licenseCopyright (c) 2023 Orphoros Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords pandas sliding window decorator function dataframe data science
VCS
bugtrack_url
requirements numpy pandas pytest pytest-cov
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pd-window-decorators

Easily apply windowing to functions that mutate Pandas DataFrames. Useful for data science projects where you want to apply a function for a DataFrame using smaller chunks of the DataFrame automatically. A moving window can be easily applied to the function using Python decorators.

## Sliding Window

To apply a sliding window, import `df_sliding_window` from `pd_window_decorators` and apply it to your function. The decorator takes a `timedelta` object as a required argument to define the slice size. By default, the decorator will look for a Pandas DataFrame named `df` in the function arguments. The DataFrame must also have a time column. The column name is `ds` by default. The decorator also expects the function to return a DataFrame.

### Example

Using the decorator with default arguments:

```python
@df_sliding_window(window_size=timedelta(days=2))
def sum_all(df):
    df.loc[:, 'sum'] = df['y'].sum()
    return df
```

Using the decorator with custom arguments:

```python
@df_sliding_window(window_size=timedelta(days=2), df_name='my_df', time_column='my_time')
def sum_all(my_df):
    df.loc[:, 'sum'] = df['y'].sum()
    return df
```

Note that in the second example, the DataFrame is named `my_df` and the `df_name` argument is set to `my_df`, so they match.

### Arguments

| Argument | Type | Optional | Description |
| --- | --- | --- | --- |
| `window_size` | `timedelta` | `True` | The size of the window to apply to the function. |
| `df_name` | `str` | `False` | The name of the DataFrame variable to pass to the function as an argument. Defaults to `df`. |
| `time_column` | `str` | `False` | The name of the column in the DataFrame that contains the time information. Defaults to `ds`. |

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pd-window-decorators",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "pandas,sliding window,decorator,function,dataframe,data science",
    "author": "",
    "author_email": "Orphoros <contact@orphoros.com>",
    "download_url": "https://files.pythonhosted.org/packages/04/c2/fcac5a0db166ed466f475020e580522cef5c17ff09e34471035650a818df/pd-window-decorators-0.0.1.tar.gz",
    "platform": null,
    "description": "# pd-window-decorators\n\nEasily apply windowing to functions that mutate Pandas DataFrames. Useful for data science projects where you want to apply a function for a DataFrame using smaller chunks of the DataFrame automatically. A moving window can be easily applied to the function using Python decorators.\n\n## Sliding Window\n\nTo apply a sliding window, import `df_sliding_window` from `pd_window_decorators` and apply it to your function. The decorator takes a `timedelta` object as a required argument to define the slice size. By default, the decorator will look for a Pandas DataFrame named `df` in the function arguments. The DataFrame must also have a time column. The column name is `ds` by default. The decorator also expects the function to return a DataFrame.\n\n### Example\n\nUsing the decorator with default arguments:\n\n```python\n@df_sliding_window(window_size=timedelta(days=2))\ndef sum_all(df):\n    df.loc[:, 'sum'] = df['y'].sum()\n    return df\n```\n\nUsing the decorator with custom arguments:\n\n```python\n@df_sliding_window(window_size=timedelta(days=2), df_name='my_df', time_column='my_time')\ndef sum_all(my_df):\n    df.loc[:, 'sum'] = df['y'].sum()\n    return df\n```\n\nNote that in the second example, the DataFrame is named `my_df` and the `df_name` argument is set to `my_df`, so they match.\n\n### Arguments\n\n| Argument | Type | Optional | Description |\n| --- | --- | --- | --- |\n| `window_size` | `timedelta` | `True` | The size of the window to apply to the function. |\n| `df_name` | `str` | `False` | The name of the DataFrame variable to pass to the function as an argument. Defaults to `df`. |\n| `time_column` | `str` | `False` | The name of the column in the DataFrame that contains the time information. Defaults to `ds`. |\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2023 Orphoros  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A decorator for applying a moving window to a function that consumes and returns a Pandas DataFrame.",
    "version": "0.0.1",
    "project_urls": {
        "documentation": "https://github.com/Orphoros/PdWindowDecorators",
        "homepage": "https://github.com/Orphoros/PdWindowDecorators",
        "repository": "https://github.com/Orphoros/PdWindowDecorators"
    },
    "split_keywords": [
        "pandas",
        "sliding window",
        "decorator",
        "function",
        "dataframe",
        "data science"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5db0c2299f80cbc714562f182bb0abab8827d24296bb6dca56c0807d084f8ec6",
                "md5": "3e6ad7c1e5c0e4c56aa2afa624b7e190",
                "sha256": "1f340d8c3451fe5a863f353a2435a5000ac161989c7f99c5068277528bbe51df"
            },
            "downloads": -1,
            "filename": "pd_window_decorators-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e6ad7c1e5c0e4c56aa2afa624b7e190",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 5037,
            "upload_time": "2024-01-20T17:10:52",
            "upload_time_iso_8601": "2024-01-20T17:10:52.781246Z",
            "url": "https://files.pythonhosted.org/packages/5d/b0/c2299f80cbc714562f182bb0abab8827d24296bb6dca56c0807d084f8ec6/pd_window_decorators-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04c2fcac5a0db166ed466f475020e580522cef5c17ff09e34471035650a818df",
                "md5": "929c5fd944f953bd0fa97973c5de07cf",
                "sha256": "dbeb221723c27ede5ac48c353a3655239abafd981875ada97325a6e1f3a516ff"
            },
            "downloads": -1,
            "filename": "pd-window-decorators-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "929c5fd944f953bd0fa97973c5de07cf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 4287,
            "upload_time": "2024-01-20T17:10:54",
            "upload_time_iso_8601": "2024-01-20T17:10:54.660369Z",
            "url": "https://files.pythonhosted.org/packages/04/c2/fcac5a0db166ed466f475020e580522cef5c17ff09e34471035650a818df/pd-window-decorators-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-20 17:10:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Orphoros",
    "github_project": "PdWindowDecorators",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "1.26.2"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    "==",
                    "2.1.4"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "7.4.3"
                ]
            ]
        },
        {
            "name": "pytest-cov",
            "specs": [
                [
                    "==",
                    "4.1.0"
                ]
            ]
        }
    ],
    "lcname": "pd-window-decorators"
}
        
Elapsed time: 0.20962s