data-drift-lite 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pranay Mahendrakar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.5
2
+ Name: data-drift-lite
3
+ Version: 0.1.0
4
+ Summary: Detect whether production data has drifted from training data, column by column, with a single call
5
+ Project-URL: Homepage, https://pypi.org/project/data-drift-lite/
6
+ Project-URL: Author, https://pypi.org/user/pranaymahendrakar/
7
+ Author: Pranay Mahendrakar
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: data drift,drift detection,kolmogorov-smirnov,mlops,model monitoring,pandas,population stability index,psi
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.9
19
+ Requires-Dist: numpy>=1.23
20
+ Requires-Dist: pandas>=1.5
21
+ Requires-Dist: scipy>=1.9
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7; extra == 'dev'
24
+ Provides-Extra: parquet
25
+ Requires-Dist: pyarrow>=12; extra == 'parquet'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # data-drift-lite
29
+
30
+ Detect whether production data has drifted from training data, column by column, with a single call.
31
+
32
+ ## Install
33
+
34
+ ```
35
+ pip install data-drift-lite
36
+ ```
37
+
38
+ Reading `.parquet` files needs `pip install "data-drift-lite[parquet]"`.
39
+
40
+ ## Quickstart
41
+
42
+ ```python
43
+ import pandas as pd
44
+ import data_drift_lite
45
+
46
+ reference = pd.DataFrame({"age": list(range(20, 60, 2)), "plan": ["basic", "pro"] * 10})
47
+ current = pd.DataFrame({"age": list(range(50, 90, 2)), "plan": ["pro"] * 18 + ["enterprise"] * 2})
48
+ report = data_drift_lite.detect(reference, current)
49
+ print(report.summary())
50
+ ```
51
+
52
+ Prints:
53
+
54
+ ```
55
+ data-drift-lite: DRIFT DETECTED: 2 of 2 columns drifted (100%)
56
+ reference rows: 20 | current rows: 20 | drifted when p < 0.05 or PSI > 0.2
57
+
58
+ column kind test statistic p-value PSI status
59
+ age numeric ks 0.7500 9.5e-06 6.4703 DRIFTED
60
+ plan categorical chi2 14.2857 0.0008 5.1829 DRIFTED
61
+
62
+ notes:
63
+ - plan: 1 category unseen in reference: 'enterprise'
64
+ ```
65
+
66
+ Then `report.drifted` is `True`, `report.drifted_columns` is `["age", "plan"]`, and
67
+ `report.to_dict()` is ready for `json.dumps`.
68
+
69
+ ## What it checks
70
+
71
+ - **Numeric columns** (ints, floats, nullable ints/floats; datetimes and timedeltas
72
+ are compared as int64 nanoseconds): a two-sample Kolmogorov-Smirnov test
73
+ (`scipy.stats.ks_2samp`) plus the Population Stability Index over 10 quantile
74
+ bins built from the reference.
75
+ - **Categorical columns** (strings, objects, `category`, and bool): a chi-square
76
+ test on category frequencies (`scipy.stats.chi2_contingency`) plus PSI over the
77
+ reference categories, with every category the reference never saw pooled into a
78
+ single extra bin.
79
+ - A column is **drifted** when `p_value < threshold` (default 0.05) **or**
80
+ `psi > psi_threshold` (default 0.2). Pass `None` for either to switch that rule off.
81
+ - **Missing values count.** They form their own bin for PSI (and their own category
82
+ in the chi-square table), so a column whose values start disappearing is flagged
83
+ even when the values that remain look the same. The KS test uses the non-missing
84
+ values. `+inf`/`-inf` are treated as missing.
85
+ - **Schema drift** is reported alongside: columns missing from the current data,
86
+ new columns, and columns whose type family changed (for example `int64 -> object`).
87
+ Missing columns and type changes set `report.drifted`; new columns are listed but
88
+ do not raise the flag.
89
+ - **Guard rails.** Constant columns get PSI 0, never NaN or inf. Numeric columns with
90
+ ten or fewer distinct values get one bin per value, so a 95/5 to 5/95 flip in a
91
+ 0/1 column is caught. A reference or batch with fewer than 20 rows produces a
92
+ warning note in the report (and a `logging` warning) instead of a crash. Each side
93
+ is capped at `sample` random rows (default 100,000, seeded by `random_state`) so a
94
+ check stays fast on big tables.
95
+
96
+ ## API
97
+
98
+ ### `detect(reference, current, *, columns=None, threshold=0.05, psi_threshold=0.2, sample=100_000, random_state=0) -> DriftReport`
99
+
100
+ The one-call path. `reference` and `current` accept a pandas DataFrame, a Series,
101
+ or a path to a `.csv` / `.parquet` file.
102
+
103
+ - `columns`: compare only these columns (default: every reference column).
104
+ - `threshold`: p-value below which a column is drifted; `None` disables the rule.
105
+ - `psi_threshold`: PSI above which a column is drifted; `None` disables the rule.
106
+ - `sample`: cap each side at this many random rows; `None` uses every row.
107
+ - `random_state`: seed for that sampling, so results are reproducible.
108
+
109
+ ### `DriftMonitor(reference, *, columns=None, threshold=0.05, psi_threshold=0.2, sample=100_000, random_state=0)`
110
+
111
+ Profiles the reference once; `monitor.check(batch)` returns a `DriftReport` for
112
+ each batch. Use it when scoring many batches against the same training data.
113
+
114
+ ```python
115
+ monitor = data_drift_lite.DriftMonitor(train_df, psi_threshold=0.1)
116
+ for batch in batches:
117
+ report = monitor.check(batch)
118
+ if report.drifted:
119
+ alert(report.summary())
120
+ ```
121
+
122
+ ### `DriftReport`
123
+
124
+ | attribute / method | meaning |
125
+ | --- | --- |
126
+ | `columns` | `dict[column -> ColumnDrift]` for every compared column, in reference order |
127
+ | `drifted_columns` | `list[str]` of the columns flagged as drifted |
128
+ | `drift_share` | fraction of compared columns that drifted |
129
+ | `drifted` | `True` if any column drifted, a column is missing, or a dtype changed |
130
+ | `missing_columns`, `new_columns`, `dtype_changed` | schema drift; `dtype_changed` maps `column -> (reference dtype, current dtype)` |
131
+ | `schema` | the same three as a `SchemaDrift` dataclass with its own `.drifted` and `.to_dict()` |
132
+ | `reference_rows`, `current_rows`, `threshold`, `psi_threshold`, `notes` | what the check ran on |
133
+ | `summary()` | human-readable text (also what `str(report)` returns) |
134
+ | `to_dict()` | JSON-safe dict: plain Python numbers, `None` for anything not computable |
135
+
136
+ ### `ColumnDrift`
137
+
138
+ Dataclass with `kind` (`"numeric"` or `"categorical"`), `test` (`"ks"` or `"chi2"`),
139
+ `statistic`, `p_value`, `psi`, `drifted`, `reference_stats`, `current_stats`,
140
+ `name`, `notes`, and `to_dict()`. Stats hold `dtype`, `count`, `missing_share`,
141
+ then `mean`/`std`/`min`/`median`/`max` for numeric columns (ISO strings for
142
+ datetimes) or `n_categories` and the `top` category shares for categorical ones.
143
+ Any statistic that could not be computed is `None`, and `notes` says why.
144
+
145
+ ## CLI
146
+
147
+ ```
148
+ data-drift-lite train.csv batch.csv
149
+ data-drift-lite train.parquet batch.parquet --columns age plan --psi-threshold 0.1
150
+ data-drift-lite train.csv batch.csv --json
151
+ data-drift-lite train.csv batch.csv --output report.json --fail-on-drift
152
+ ```
153
+
154
+ `data-drift-lite REFERENCE CURRENT` prints the summary. Options:
155
+
156
+ - `--columns COL [COL ...]`, `--threshold P`, `--psi-threshold PSI`,
157
+ `--sample N` (0 disables sampling), `--random-state SEED` mirror `detect()`.
158
+ - `--json` prints `to_dict()` as JSON instead of the summary.
159
+ - `--output PATH` also writes that JSON to a file.
160
+ - `--fail-on-drift` exits with status 1 when drift is detected, for CI and cron jobs.
161
+ - `--version`, `--help`.
162
+
163
+ ## License
164
+
165
+ MIT
@@ -0,0 +1,138 @@
1
+ # data-drift-lite
2
+
3
+ Detect whether production data has drifted from training data, column by column, with a single call.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ pip install data-drift-lite
9
+ ```
10
+
11
+ Reading `.parquet` files needs `pip install "data-drift-lite[parquet]"`.
12
+
13
+ ## Quickstart
14
+
15
+ ```python
16
+ import pandas as pd
17
+ import data_drift_lite
18
+
19
+ reference = pd.DataFrame({"age": list(range(20, 60, 2)), "plan": ["basic", "pro"] * 10})
20
+ current = pd.DataFrame({"age": list(range(50, 90, 2)), "plan": ["pro"] * 18 + ["enterprise"] * 2})
21
+ report = data_drift_lite.detect(reference, current)
22
+ print(report.summary())
23
+ ```
24
+
25
+ Prints:
26
+
27
+ ```
28
+ data-drift-lite: DRIFT DETECTED: 2 of 2 columns drifted (100%)
29
+ reference rows: 20 | current rows: 20 | drifted when p < 0.05 or PSI > 0.2
30
+
31
+ column kind test statistic p-value PSI status
32
+ age numeric ks 0.7500 9.5e-06 6.4703 DRIFTED
33
+ plan categorical chi2 14.2857 0.0008 5.1829 DRIFTED
34
+
35
+ notes:
36
+ - plan: 1 category unseen in reference: 'enterprise'
37
+ ```
38
+
39
+ Then `report.drifted` is `True`, `report.drifted_columns` is `["age", "plan"]`, and
40
+ `report.to_dict()` is ready for `json.dumps`.
41
+
42
+ ## What it checks
43
+
44
+ - **Numeric columns** (ints, floats, nullable ints/floats; datetimes and timedeltas
45
+ are compared as int64 nanoseconds): a two-sample Kolmogorov-Smirnov test
46
+ (`scipy.stats.ks_2samp`) plus the Population Stability Index over 10 quantile
47
+ bins built from the reference.
48
+ - **Categorical columns** (strings, objects, `category`, and bool): a chi-square
49
+ test on category frequencies (`scipy.stats.chi2_contingency`) plus PSI over the
50
+ reference categories, with every category the reference never saw pooled into a
51
+ single extra bin.
52
+ - A column is **drifted** when `p_value < threshold` (default 0.05) **or**
53
+ `psi > psi_threshold` (default 0.2). Pass `None` for either to switch that rule off.
54
+ - **Missing values count.** They form their own bin for PSI (and their own category
55
+ in the chi-square table), so a column whose values start disappearing is flagged
56
+ even when the values that remain look the same. The KS test uses the non-missing
57
+ values. `+inf`/`-inf` are treated as missing.
58
+ - **Schema drift** is reported alongside: columns missing from the current data,
59
+ new columns, and columns whose type family changed (for example `int64 -> object`).
60
+ Missing columns and type changes set `report.drifted`; new columns are listed but
61
+ do not raise the flag.
62
+ - **Guard rails.** Constant columns get PSI 0, never NaN or inf. Numeric columns with
63
+ ten or fewer distinct values get one bin per value, so a 95/5 to 5/95 flip in a
64
+ 0/1 column is caught. A reference or batch with fewer than 20 rows produces a
65
+ warning note in the report (and a `logging` warning) instead of a crash. Each side
66
+ is capped at `sample` random rows (default 100,000, seeded by `random_state`) so a
67
+ check stays fast on big tables.
68
+
69
+ ## API
70
+
71
+ ### `detect(reference, current, *, columns=None, threshold=0.05, psi_threshold=0.2, sample=100_000, random_state=0) -> DriftReport`
72
+
73
+ The one-call path. `reference` and `current` accept a pandas DataFrame, a Series,
74
+ or a path to a `.csv` / `.parquet` file.
75
+
76
+ - `columns`: compare only these columns (default: every reference column).
77
+ - `threshold`: p-value below which a column is drifted; `None` disables the rule.
78
+ - `psi_threshold`: PSI above which a column is drifted; `None` disables the rule.
79
+ - `sample`: cap each side at this many random rows; `None` uses every row.
80
+ - `random_state`: seed for that sampling, so results are reproducible.
81
+
82
+ ### `DriftMonitor(reference, *, columns=None, threshold=0.05, psi_threshold=0.2, sample=100_000, random_state=0)`
83
+
84
+ Profiles the reference once; `monitor.check(batch)` returns a `DriftReport` for
85
+ each batch. Use it when scoring many batches against the same training data.
86
+
87
+ ```python
88
+ monitor = data_drift_lite.DriftMonitor(train_df, psi_threshold=0.1)
89
+ for batch in batches:
90
+ report = monitor.check(batch)
91
+ if report.drifted:
92
+ alert(report.summary())
93
+ ```
94
+
95
+ ### `DriftReport`
96
+
97
+ | attribute / method | meaning |
98
+ | --- | --- |
99
+ | `columns` | `dict[column -> ColumnDrift]` for every compared column, in reference order |
100
+ | `drifted_columns` | `list[str]` of the columns flagged as drifted |
101
+ | `drift_share` | fraction of compared columns that drifted |
102
+ | `drifted` | `True` if any column drifted, a column is missing, or a dtype changed |
103
+ | `missing_columns`, `new_columns`, `dtype_changed` | schema drift; `dtype_changed` maps `column -> (reference dtype, current dtype)` |
104
+ | `schema` | the same three as a `SchemaDrift` dataclass with its own `.drifted` and `.to_dict()` |
105
+ | `reference_rows`, `current_rows`, `threshold`, `psi_threshold`, `notes` | what the check ran on |
106
+ | `summary()` | human-readable text (also what `str(report)` returns) |
107
+ | `to_dict()` | JSON-safe dict: plain Python numbers, `None` for anything not computable |
108
+
109
+ ### `ColumnDrift`
110
+
111
+ Dataclass with `kind` (`"numeric"` or `"categorical"`), `test` (`"ks"` or `"chi2"`),
112
+ `statistic`, `p_value`, `psi`, `drifted`, `reference_stats`, `current_stats`,
113
+ `name`, `notes`, and `to_dict()`. Stats hold `dtype`, `count`, `missing_share`,
114
+ then `mean`/`std`/`min`/`median`/`max` for numeric columns (ISO strings for
115
+ datetimes) or `n_categories` and the `top` category shares for categorical ones.
116
+ Any statistic that could not be computed is `None`, and `notes` says why.
117
+
118
+ ## CLI
119
+
120
+ ```
121
+ data-drift-lite train.csv batch.csv
122
+ data-drift-lite train.parquet batch.parquet --columns age plan --psi-threshold 0.1
123
+ data-drift-lite train.csv batch.csv --json
124
+ data-drift-lite train.csv batch.csv --output report.json --fail-on-drift
125
+ ```
126
+
127
+ `data-drift-lite REFERENCE CURRENT` prints the summary. Options:
128
+
129
+ - `--columns COL [COL ...]`, `--threshold P`, `--psi-threshold PSI`,
130
+ `--sample N` (0 disables sampling), `--random-state SEED` mirror `detect()`.
131
+ - `--json` prints `to_dict()` as JSON instead of the summary.
132
+ - `--output PATH` also writes that JSON to a file.
133
+ - `--fail-on-drift` exits with status 1 when drift is detected, for CI and cron jobs.
134
+ - `--version`, `--help`.
135
+
136
+ ## License
137
+
138
+ MIT
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "data-drift-lite"
7
+ version = "0.1.0"
8
+ description = "Detect whether production data has drifted from training data, column by column, with a single call"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Pranay Mahendrakar" }]
14
+ keywords = [
15
+ "data drift",
16
+ "drift detection",
17
+ "population stability index",
18
+ "psi",
19
+ "kolmogorov-smirnov",
20
+ "model monitoring",
21
+ "mlops",
22
+ "pandas",
23
+ ]
24
+ classifiers = [
25
+ "Development Status :: 4 - Beta",
26
+ "Intended Audience :: Developers",
27
+ "Intended Audience :: Science/Research",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3 :: Only",
30
+ "Operating System :: OS Independent",
31
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
32
+ ]
33
+ dependencies = [
34
+ "pandas>=1.5",
35
+ "numpy>=1.23",
36
+ "scipy>=1.9",
37
+ ]
38
+
39
+ [project.optional-dependencies]
40
+ parquet = ["pyarrow>=12"]
41
+ dev = ["pytest>=7"]
42
+
43
+ [project.scripts]
44
+ data-drift-lite = "data_drift_lite.cli:main"
45
+
46
+ [project.urls]
47
+ Homepage = "https://pypi.org/project/data-drift-lite/"
48
+ Author = "https://pypi.org/user/pranaymahendrakar/"
49
+
50
+ [tool.hatch.build.targets.wheel]
51
+ packages = ["src/data_drift_lite"]
@@ -0,0 +1,20 @@
1
+ """Detect whether production data has drifted from training data, column by column.
2
+
3
+ import data_drift_lite
4
+ report = data_drift_lite.detect(reference_df, current_df)
5
+ report.drifted, report.drifted_columns, report.summary(), report.to_dict()
6
+ """
7
+
8
+ from ._core import DriftMonitor, detect
9
+ from ._report import ColumnDrift, DriftReport, SchemaDrift
10
+
11
+ __version__ = "0.1.0"
12
+
13
+ __all__ = [
14
+ "detect",
15
+ "DriftMonitor",
16
+ "DriftReport",
17
+ "ColumnDrift",
18
+ "SchemaDrift",
19
+ "__version__",
20
+ ]
@@ -0,0 +1,8 @@
1
+ """Allow ``python -m data_drift_lite reference.csv current.csv``."""
2
+
3
+ import sys
4
+
5
+ from .cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())