Metadata-Version: 2.1
Name: pd-window-decorators
Version: 0.0.1
Summary: A decorator for applying a moving window to a function that consumes and returns a Pandas DataFrame.
Author-email: Orphoros <contact@orphoros.com>
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.
Project-URL: homepage, https://github.com/Orphoros/PdWindowDecorators
Project-URL: documentation, https://github.com/Orphoros/PdWindowDecorators
Project-URL: repository, https://github.com/Orphoros/PdWindowDecorators
Keywords: pandas,sliding window,decorator,function,dataframe,data science
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=1.3.0
Requires-Dist: numpy>=1.21.0

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