Metadata-Version: 2.4
Name: mis_analytics
Version: 0.0.5
Summary: Helpers for data work in supply chain analytics (and others?)
Author-email: Jan Hesse and Jonas Jakubassa <jhesse@mis-analytics.de>
License: Apache-2.0
Project-URL: Repository, https://github.com/MIS-Analytics/mis_analytics
Project-URL: Documentation, https://MIS-Analytics.github.io/mis_analytics
Keywords: etl,,sap,,nbdev
Classifier: Natural Language :: English
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas
Requires-Dist: numpy
Requires-Dist: polars>=1.40.0
Requires-Dist: pyarrow>=25.0.1
Provides-Extra: desapher
Requires-Dist: httpx; extra == "desapher"
Requires-Dist: beautifulsoup4; extra == "desapher"
Requires-Dist: lxml; extra == "desapher"
Provides-Extra: dev
Requires-Dist: dialoghelper>=0.2.43; extra == "dev"
Requires-Dist: fastcore>=2.2.27; extra == "dev"
Requires-Dist: nbdev>=3.3.18; extra == "dev"
Dynamic: license-file

# mis_analytics


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

`mis_analytics` helps prepare supply chain and manufacturing data. Clean columns and resample time series, inspect pandas and eager Polars pipelines, and use deSAPher to look up SAP fields and convert SAP extracts.

## Installation

Requires Python 3.11 or later. Install the DataFrame utilities and pipeline tracking:

``` sh
pip install mis_analytics
```

For SAP functionality, install the `desapher` extra:

``` sh
pip install "mis_analytics[desapher]"
```

The extra adds `httpx`, `beautifulsoup4`, and `lxml`. The base package includes pandas, NumPy, and Polars. Import `mis_analytics.desapher` only when its extra dependencies are installed.

To install the latest code from GitHub, including the extra:

``` sh
pip install "mis_analytics[desapher] @ git+https://github.com/MIS-Analytics/mis_analytics.git"
```

Omit `[desapher]` for the base package.

## DataFrame utilities

``` python
import pandas as pd
import polars as pl
from mis_analytics.core import clean_col_names
from mis_analytics.etl import track
```

``` python
orders = pd.DataFrame({'Order ID': [101, 102, 103], 'Quantity': [5, 10, 15]})
orders = clean_col_names(orders)
orders
```

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }
&#10;    .dataframe tbody tr th {
        vertical-align: top;
    }
&#10;    .dataframe thead th {
        text-align: right;
    }
</style>

|     | order_id | product  | quantity | defects | production_time |
|-----|----------|----------|----------|---------|-----------------|
| 0   | 101      | Widget A | 50       | 2       | 120             |
| 1   | 102      | Widget B | 30       | 1       | 95              |
| 2   | 103      | Widget A | 75       | 3       | 150             |
| 3   | 104      | Widget C | 20       | 0       | 80              |
| 4   | 105      | Widget B | 45       | 2       | 110             |

</div>

## Pipeline tracking

Decorate a function with `@track` and chain it with `.pipe()`. Set `vrbs=True` on each step to print its name, docstring, elapsed time, shape changes, and input/output samples. Logging is off by default. Both pandas and eager Polars DataFrames are supported; each transformation must support the DataFrame it receives.

``` python
@track
def take_rows(df, n):
    """Keep the first n rows."""
    return df.head(n)
```

``` python
pandas_preview = orders.pipe(take_rows, 2, vrbs=True).pipe(take_rows, 1, vrbs=True)
polars_orders = pl.DataFrame({'order_id': [101, 102, 103], 'quantity': [5, 10, 15]})
polars_preview = polars_orders.pipe(take_rows, 2, vrbs=True).pipe(take_rows, 1, vrbs=True)
```

## SAP helpers with deSAPher

With the `desapher` extra installed, fetch SAP table metadata from sapdatasheet.org and use it to convert types and rename fields in pandas extracts. Fetching metadata requires internet access.

``` python
from mis_analytics.desapher import get_sap_tables_structure, convert_sap_types, rename_sap_columns

sap_sheet = get_sap_tables_structure(['MARA'])
materials = pd.DataFrame({'MATNR': ['000000000000000101']})
if sap_sheet is not None:
    materials = materials.pipe(convert_sap_types, sap_sheet).pipe(rename_sap_columns, sap_sheet)
```

[`get_sap_table_description`](https://MIS-Analytics.github.io/mis_analytics/desapher.html#get_sap_table_description) also retrieves a table’s description.

## Development

From a local checkout, install the development group and SAP extra:

``` sh
uv sync --group dev --extra desapher
```

Edit the source notebooks under `nbs/`, then export the modules. Regenerate the README after editing `nbs/index.ipynb`:

``` sh
uv run nbdev-export
uv run nbdev-test --path nbs/index.ipynb
uv run nbdev-readme
```

[API documentation](https://MIS-Analytics.github.io/mis_analytics/) · [Source code](https://github.com/MIS-Analytics/mis_analytics)
