dsdiff 0.2.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.
- dsdiff-0.2.0/.github/workflows/ci.yml +28 -0
- dsdiff-0.2.0/.github/workflows/publish.yml +21 -0
- dsdiff-0.2.0/.gitignore +26 -0
- dsdiff-0.2.0/.pre-commit-config.yaml +15 -0
- dsdiff-0.2.0/CHANGELOG.md +30 -0
- dsdiff-0.2.0/Dockerfile +19 -0
- dsdiff-0.2.0/LICENSE +21 -0
- dsdiff-0.2.0/PKG-INFO +138 -0
- dsdiff-0.2.0/README.md +90 -0
- dsdiff-0.2.0/pyproject.toml +72 -0
- dsdiff-0.2.0/src/dsdiff/__init__.py +19 -0
- dsdiff-0.2.0/src/dsdiff/__main__.py +4 -0
- dsdiff-0.2.0/src/dsdiff/cli.py +114 -0
- dsdiff-0.2.0/src/dsdiff/compare.py +161 -0
- dsdiff-0.2.0/src/dsdiff/dataset.py +174 -0
- dsdiff-0.2.0/src/dsdiff/drift.py +63 -0
- dsdiff-0.2.0/src/dsdiff/profile.py +151 -0
- dsdiff-0.2.0/src/dsdiff/render.py +55 -0
- dsdiff-0.2.0/tests/test_cli.py +78 -0
- dsdiff-0.2.0/tests/test_compare.py +85 -0
- dsdiff-0.2.0/tests/test_dataset.py +59 -0
- dsdiff-0.2.0/tests/test_drift.py +53 -0
- dsdiff-0.2.0/tests/test_profile.py +67 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- name: Install uv
|
|
18
|
+
uses: astral-sh/setup-uv@v3
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python-version }}
|
|
21
|
+
- name: Sync dependencies
|
|
22
|
+
run: uv sync --all-extras --dev
|
|
23
|
+
- name: Lint
|
|
24
|
+
run: uv run ruff check .
|
|
25
|
+
- name: Format check
|
|
26
|
+
run: uv run ruff format --check .
|
|
27
|
+
- name: Test
|
|
28
|
+
run: uv run pytest --cov --cov-report=term-missing
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
pypi:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: pypi
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v3
|
|
18
|
+
- name: Build
|
|
19
|
+
run: uv build
|
|
20
|
+
- name: Publish to PyPI
|
|
21
|
+
run: uv publish
|
dsdiff-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
|
|
9
|
+
# Virtual environments
|
|
10
|
+
.venv/
|
|
11
|
+
venv/
|
|
12
|
+
|
|
13
|
+
# uv
|
|
14
|
+
uv.lock
|
|
15
|
+
|
|
16
|
+
# Test and coverage
|
|
17
|
+
.pytest_cache/
|
|
18
|
+
.coverage
|
|
19
|
+
.coverage.*
|
|
20
|
+
htmlcov/
|
|
21
|
+
.ruff_cache/
|
|
22
|
+
|
|
23
|
+
# Editor / OS
|
|
24
|
+
.vscode/
|
|
25
|
+
.idea/
|
|
26
|
+
.DS_Store
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.6.9
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
9
|
+
rev: v4.6.0
|
|
10
|
+
hooks:
|
|
11
|
+
- id: end-of-file-fixer
|
|
12
|
+
- id: trailing-whitespace
|
|
13
|
+
- id: check-yaml
|
|
14
|
+
- id: check-toml
|
|
15
|
+
- id: check-merge-conflict
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based
|
|
4
|
+
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
|
+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.2.0] - 2026-06-08
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- `--fail-on medium` to tighten the `--check` gate beyond high-severity only.
|
|
11
|
+
- Markdown output for pasting a diff into a pull request.
|
|
12
|
+
- Docker image and a published container entry point.
|
|
13
|
+
- Continuous integration across Python 3.10, 3.11 and 3.12.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Drift is no longer missed when a column shifts entirely past the baseline
|
|
17
|
+
range; out-of-range values are clamped to the edge bins.
|
|
18
|
+
|
|
19
|
+
## [0.1.0] - 2026-06-03
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- `diff` command: schema changes (added, removed, retyped columns), null-rate
|
|
23
|
+
jumps, cardinality changes, and per-column distribution drift via PSI.
|
|
24
|
+
- `profile` command: write a committable baseline profile with bin edges so a
|
|
25
|
+
later diff measures drift against the same buckets.
|
|
26
|
+
- CSV, Parquet and JSON Lines input through polars.
|
|
27
|
+
- `--json` output and a `--check` CI gate.
|
|
28
|
+
|
|
29
|
+
[0.2.0]: https://github.com/jmweb-org/dsdiff/releases/tag/v0.2.0
|
|
30
|
+
[0.1.0]: https://github.com/jmweb-org/dsdiff/releases/tag/v0.1.0
|
dsdiff-0.2.0/Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Diff two datasets from inside a container by mounting them:
|
|
2
|
+
#
|
|
3
|
+
# docker build -t dsdiff .
|
|
4
|
+
# docker run --rm -v "$PWD:/w" -w /w dsdiff diff a.parquet b.parquet
|
|
5
|
+
#
|
|
6
|
+
FROM python:3.12-slim
|
|
7
|
+
|
|
8
|
+
LABEL org.opencontainers.image.source="https://github.com/jmweb-org/dsdiff"
|
|
9
|
+
LABEL org.opencontainers.image.description="Diff two dataset files: schema changes plus column-level distribution drift."
|
|
10
|
+
LABEL org.opencontainers.image.licenses="MIT"
|
|
11
|
+
|
|
12
|
+
WORKDIR /app
|
|
13
|
+
COPY pyproject.toml README.md LICENSE ./
|
|
14
|
+
COPY src ./src
|
|
15
|
+
|
|
16
|
+
RUN pip install --no-cache-dir .
|
|
17
|
+
|
|
18
|
+
ENTRYPOINT ["dsdiff"]
|
|
19
|
+
CMD ["--help"]
|
dsdiff-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 José del Río
|
|
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.
|
dsdiff-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dsdiff
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Diff two dataset files: schema changes plus column-level distribution drift.
|
|
5
|
+
Project-URL: Homepage, https://github.com/jmweb-org/dsdiff
|
|
6
|
+
Project-URL: Repository, https://github.com/jmweb-org/dsdiff
|
|
7
|
+
Project-URL: Issues, https://github.com/jmweb-org/dsdiff/issues
|
|
8
|
+
Author: José del Río
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 José del Río
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: cli,data,dataset,diff,drift,mlops,psi,schema
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Topic :: Scientific/Engineering
|
|
41
|
+
Classifier: Topic :: Utilities
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Requires-Dist: numpy>=1.24
|
|
44
|
+
Requires-Dist: polars>=1.0
|
|
45
|
+
Requires-Dist: rich>=13.0
|
|
46
|
+
Requires-Dist: typer>=0.12
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# dsdiff
|
|
50
|
+
|
|
51
|
+
[](https://github.com/jmweb-org/dsdiff/actions/workflows/ci.yml)
|
|
52
|
+
[](https://pypi.org/project/dsdiff/)
|
|
53
|
+
[](https://www.python.org)
|
|
54
|
+
[](LICENSE)
|
|
55
|
+
|
|
56
|
+
A git-style diff between two dataset files: schema changes and column-level
|
|
57
|
+
distribution drift, with a CI gate.
|
|
58
|
+
|
|
59
|
+
When a dataset is regenerated, columns quietly get renamed, retyped, gain
|
|
60
|
+
nulls, or shift distribution, and the pipeline keeps running while the model
|
|
61
|
+
degrades. There is no quick "git diff for data" a reviewer can read on a pull
|
|
62
|
+
request. `dsdiff` is that: point it at two files and it reports what changed,
|
|
63
|
+
ranked by how much it should worry you.
|
|
64
|
+
|
|
65
|
+
```console
|
|
66
|
+
$ dsdiff diff yesterday.parquet today.parquet
|
|
67
|
+
severity column change detail
|
|
68
|
+
high income drift PSI 0.412
|
|
69
|
+
high signup_date column_added new column
|
|
70
|
+
medium age null_rate null rate 0.0% -> 7.3%
|
|
71
|
+
low country cardinality distinct values 41 -> 44
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Install
|
|
75
|
+
|
|
76
|
+
```console
|
|
77
|
+
$ pip install dsdiff # from PyPI, once released
|
|
78
|
+
$ pip install git+https://github.com/jmweb-org/dsdiff # latest, available now
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Reads CSV, Parquet and JSON Lines through polars. No services, no schema files
|
|
82
|
+
to author.
|
|
83
|
+
|
|
84
|
+
## Usage
|
|
85
|
+
|
|
86
|
+
```console
|
|
87
|
+
$ dsdiff diff a.csv b.csv # human-readable table
|
|
88
|
+
$ dsdiff diff a.csv b.csv --json # machine-readable findings
|
|
89
|
+
$ dsdiff diff a.csv b.csv --markdown # a table to paste into a PR
|
|
90
|
+
$ dsdiff diff a.csv b.csv --check # exit non-zero on a high-severity change
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Commit a baseline
|
|
94
|
+
|
|
95
|
+
Profile a dataset once and compare future data against the saved profile,
|
|
96
|
+
without re-reading the original file:
|
|
97
|
+
|
|
98
|
+
```console
|
|
99
|
+
$ dsdiff profile reference.parquet -o baseline.json
|
|
100
|
+
$ dsdiff diff baseline.json new_batch.parquet --check
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The baseline stores the bin edges, so drift on `new_batch` is measured against
|
|
104
|
+
exactly the same buckets as the reference.
|
|
105
|
+
|
|
106
|
+
### In CI
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
- run: dsdiff diff baseline.json data/current.parquet --check
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## What it checks
|
|
113
|
+
|
|
114
|
+
- **Schema**: columns added, removed, or retyped (all high severity).
|
|
115
|
+
- **Nulls**: a jump in the null rate of a shared column.
|
|
116
|
+
- **Cardinality**: a categorical column gaining or losing distinct values.
|
|
117
|
+
- **Distribution drift**: the population stability index (PSI) per column,
|
|
118
|
+
numeric columns binned by quantiles and categoricals by frequency.
|
|
119
|
+
|
|
120
|
+
## Severity and the PSI scale
|
|
121
|
+
|
|
122
|
+
PSI is the standard tabular drift measure. The conventional reading is used
|
|
123
|
+
here: below 0.1 is **low** (no meaningful shift), 0.1 to 0.25 is **medium**,
|
|
124
|
+
and 0.25 or above is **high**. Schema and type changes are always high. By
|
|
125
|
+
default `--check` fails only on high-severity findings; pass `--fail-on medium`
|
|
126
|
+
to tighten the gate.
|
|
127
|
+
|
|
128
|
+
## Exit codes
|
|
129
|
+
|
|
130
|
+
| Code | Meaning |
|
|
131
|
+
| --- | --- |
|
|
132
|
+
| 0 | Ran; no blocking finding (or `--check` not set) |
|
|
133
|
+
| 1 | `--check` found a finding at or above the fail threshold |
|
|
134
|
+
| 2 | A file was missing or in an unsupported format |
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT. See [LICENSE](LICENSE).
|
dsdiff-0.2.0/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# dsdiff
|
|
2
|
+
|
|
3
|
+
[](https://github.com/jmweb-org/dsdiff/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/dsdiff/)
|
|
5
|
+
[](https://www.python.org)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
A git-style diff between two dataset files: schema changes and column-level
|
|
9
|
+
distribution drift, with a CI gate.
|
|
10
|
+
|
|
11
|
+
When a dataset is regenerated, columns quietly get renamed, retyped, gain
|
|
12
|
+
nulls, or shift distribution, and the pipeline keeps running while the model
|
|
13
|
+
degrades. There is no quick "git diff for data" a reviewer can read on a pull
|
|
14
|
+
request. `dsdiff` is that: point it at two files and it reports what changed,
|
|
15
|
+
ranked by how much it should worry you.
|
|
16
|
+
|
|
17
|
+
```console
|
|
18
|
+
$ dsdiff diff yesterday.parquet today.parquet
|
|
19
|
+
severity column change detail
|
|
20
|
+
high income drift PSI 0.412
|
|
21
|
+
high signup_date column_added new column
|
|
22
|
+
medium age null_rate null rate 0.0% -> 7.3%
|
|
23
|
+
low country cardinality distinct values 41 -> 44
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```console
|
|
29
|
+
$ pip install dsdiff # from PyPI, once released
|
|
30
|
+
$ pip install git+https://github.com/jmweb-org/dsdiff # latest, available now
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Reads CSV, Parquet and JSON Lines through polars. No services, no schema files
|
|
34
|
+
to author.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```console
|
|
39
|
+
$ dsdiff diff a.csv b.csv # human-readable table
|
|
40
|
+
$ dsdiff diff a.csv b.csv --json # machine-readable findings
|
|
41
|
+
$ dsdiff diff a.csv b.csv --markdown # a table to paste into a PR
|
|
42
|
+
$ dsdiff diff a.csv b.csv --check # exit non-zero on a high-severity change
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Commit a baseline
|
|
46
|
+
|
|
47
|
+
Profile a dataset once and compare future data against the saved profile,
|
|
48
|
+
without re-reading the original file:
|
|
49
|
+
|
|
50
|
+
```console
|
|
51
|
+
$ dsdiff profile reference.parquet -o baseline.json
|
|
52
|
+
$ dsdiff diff baseline.json new_batch.parquet --check
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The baseline stores the bin edges, so drift on `new_batch` is measured against
|
|
56
|
+
exactly the same buckets as the reference.
|
|
57
|
+
|
|
58
|
+
### In CI
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
- run: dsdiff diff baseline.json data/current.parquet --check
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## What it checks
|
|
65
|
+
|
|
66
|
+
- **Schema**: columns added, removed, or retyped (all high severity).
|
|
67
|
+
- **Nulls**: a jump in the null rate of a shared column.
|
|
68
|
+
- **Cardinality**: a categorical column gaining or losing distinct values.
|
|
69
|
+
- **Distribution drift**: the population stability index (PSI) per column,
|
|
70
|
+
numeric columns binned by quantiles and categoricals by frequency.
|
|
71
|
+
|
|
72
|
+
## Severity and the PSI scale
|
|
73
|
+
|
|
74
|
+
PSI is the standard tabular drift measure. The conventional reading is used
|
|
75
|
+
here: below 0.1 is **low** (no meaningful shift), 0.1 to 0.25 is **medium**,
|
|
76
|
+
and 0.25 or above is **high**. Schema and type changes are always high. By
|
|
77
|
+
default `--check` fails only on high-severity findings; pass `--fail-on medium`
|
|
78
|
+
to tighten the gate.
|
|
79
|
+
|
|
80
|
+
## Exit codes
|
|
81
|
+
|
|
82
|
+
| Code | Meaning |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| 0 | Ran; no blocking finding (or `--check` not set) |
|
|
85
|
+
| 1 | `--check` found a finding at or above the fail threshold |
|
|
86
|
+
| 2 | A file was missing or in an unsupported format |
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dsdiff"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Diff two dataset files: schema changes plus column-level distribution drift."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [{ name = "José del Río" }]
|
|
13
|
+
keywords = ["data", "dataset", "drift", "psi", "schema", "diff", "mlops", "cli"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Scientific/Engineering",
|
|
24
|
+
"Topic :: Utilities",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"typer>=0.12",
|
|
28
|
+
"rich>=13.0",
|
|
29
|
+
"polars>=1.0",
|
|
30
|
+
"numpy>=1.24",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/jmweb-org/dsdiff"
|
|
35
|
+
Repository = "https://github.com/jmweb-org/dsdiff"
|
|
36
|
+
Issues = "https://github.com/jmweb-org/dsdiff/issues"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
dsdiff = "dsdiff.cli:entrypoint"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest>=8.0",
|
|
44
|
+
"pytest-cov>=5.0",
|
|
45
|
+
"ruff>=0.6",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.wheel]
|
|
49
|
+
packages = ["src/dsdiff"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
addopts = "-q"
|
|
53
|
+
testpaths = ["tests"]
|
|
54
|
+
pythonpath = ["."]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
line-length = 100
|
|
58
|
+
target-version = "py310"
|
|
59
|
+
src = ["src", "tests"]
|
|
60
|
+
|
|
61
|
+
[tool.ruff.lint]
|
|
62
|
+
select = ["E", "F", "I", "UP", "B", "S", "C4", "RUF"]
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint.flake8-bugbear]
|
|
65
|
+
extend-immutable-calls = ["typer.Argument", "typer.Option"]
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint.per-file-ignores]
|
|
68
|
+
"tests/*" = ["S101"]
|
|
69
|
+
|
|
70
|
+
[tool.coverage.run]
|
|
71
|
+
source = ["dsdiff"]
|
|
72
|
+
branch = true
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""dsdiff: diff two dataset files by schema and column-level drift."""
|
|
2
|
+
|
|
3
|
+
from dsdiff.compare import Finding, FindingKind, compare_files, compare_profiles
|
|
4
|
+
from dsdiff.dataset import DatasetProfile, profile_file
|
|
5
|
+
from dsdiff.drift import Severity, psi_from_counts
|
|
6
|
+
|
|
7
|
+
__version__ = "0.2.0"
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"DatasetProfile",
|
|
11
|
+
"Finding",
|
|
12
|
+
"FindingKind",
|
|
13
|
+
"Severity",
|
|
14
|
+
"__version__",
|
|
15
|
+
"compare_files",
|
|
16
|
+
"compare_profiles",
|
|
17
|
+
"profile_file",
|
|
18
|
+
"psi_from_counts",
|
|
19
|
+
]
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Command-line interface for dsdiff."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
from rich.console import Console
|
|
12
|
+
|
|
13
|
+
from dsdiff import __version__
|
|
14
|
+
from dsdiff.compare import compare_files, has_blocking
|
|
15
|
+
from dsdiff.dataset import profile_file
|
|
16
|
+
from dsdiff.drift import Severity
|
|
17
|
+
from dsdiff.render import findings_to_json, render_markdown, render_terminal
|
|
18
|
+
|
|
19
|
+
app = typer.Typer(
|
|
20
|
+
add_completion=False,
|
|
21
|
+
no_args_is_help=True,
|
|
22
|
+
help="Diff two dataset files: schema changes plus column-level drift.",
|
|
23
|
+
)
|
|
24
|
+
_out = Console()
|
|
25
|
+
_err = Console(stderr=True)
|
|
26
|
+
|
|
27
|
+
EXIT_OK = 0
|
|
28
|
+
EXIT_BLOCKING = 1
|
|
29
|
+
EXIT_BAD_INPUT = 2
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class FailOn(str, Enum):
|
|
33
|
+
high = "high"
|
|
34
|
+
medium = "medium"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _version_callback(value: bool) -> None:
|
|
38
|
+
if value:
|
|
39
|
+
_out.print(f"dsdiff {__version__}")
|
|
40
|
+
raise typer.Exit()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@app.callback()
|
|
44
|
+
def main(
|
|
45
|
+
_version: bool = typer.Option(
|
|
46
|
+
False,
|
|
47
|
+
"--version",
|
|
48
|
+
callback=_version_callback,
|
|
49
|
+
is_eager=True,
|
|
50
|
+
help="Show the version and exit.",
|
|
51
|
+
),
|
|
52
|
+
) -> None:
|
|
53
|
+
"""dsdiff command-line interface."""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@app.command("diff")
|
|
57
|
+
def diff(
|
|
58
|
+
baseline: Path = typer.Argument(..., help="Baseline dataset, or a saved profile JSON."),
|
|
59
|
+
candidate: Path = typer.Argument(..., help="Dataset to compare against the baseline."),
|
|
60
|
+
as_json: bool = typer.Option(False, "--json", help="Emit findings as JSON."),
|
|
61
|
+
markdown: bool = typer.Option(False, "--markdown", help="Emit a Markdown table."),
|
|
62
|
+
check: bool = typer.Option(False, "--check", help="Exit non-zero on blocking findings."),
|
|
63
|
+
fail_on: FailOn = typer.Option(
|
|
64
|
+
FailOn.high, "--fail-on", help="Severity that --check treats as blocking."
|
|
65
|
+
),
|
|
66
|
+
) -> None:
|
|
67
|
+
"""Compare two datasets and report schema and distribution changes."""
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
findings = compare_files(baseline, candidate)
|
|
71
|
+
except (OSError, ValueError, json.JSONDecodeError) as exc:
|
|
72
|
+
_err.print(f"dsdiff: {exc}")
|
|
73
|
+
raise typer.Exit(EXIT_BAD_INPUT) from exc
|
|
74
|
+
|
|
75
|
+
if as_json:
|
|
76
|
+
_out.print_json(json.dumps(findings_to_json(findings)))
|
|
77
|
+
elif markdown:
|
|
78
|
+
_out.print(render_markdown(findings))
|
|
79
|
+
else:
|
|
80
|
+
_out.print(render_terminal(findings))
|
|
81
|
+
|
|
82
|
+
threshold = Severity.HIGH if fail_on is FailOn.high else Severity.MEDIUM
|
|
83
|
+
if check and has_blocking(findings, threshold):
|
|
84
|
+
raise typer.Exit(EXIT_BLOCKING)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@app.command("profile")
|
|
88
|
+
def profile(
|
|
89
|
+
dataset: Path = typer.Argument(..., help="Dataset to profile."),
|
|
90
|
+
output: Path | None = typer.Option(
|
|
91
|
+
None, "-o", "--output", help="Write the profile JSON here (default: stdout)."
|
|
92
|
+
),
|
|
93
|
+
) -> None:
|
|
94
|
+
"""Write a committable baseline profile of a dataset."""
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
prof = profile_file(dataset)
|
|
98
|
+
except (OSError, ValueError) as exc:
|
|
99
|
+
_err.print(f"dsdiff: {exc}")
|
|
100
|
+
raise typer.Exit(EXIT_BAD_INPUT) from exc
|
|
101
|
+
payload = json.dumps(prof.to_dict(), indent=2)
|
|
102
|
+
if output is None:
|
|
103
|
+
_out.print_json(payload)
|
|
104
|
+
else:
|
|
105
|
+
Path(output).write_text(payload + "\n", encoding="utf-8")
|
|
106
|
+
_err.print(f"dsdiff: wrote {output}")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def entrypoint() -> None:
|
|
110
|
+
try:
|
|
111
|
+
app()
|
|
112
|
+
except KeyboardInterrupt: # pragma: no cover - interactive only
|
|
113
|
+
print("dsdiff: interrupted", file=sys.stderr)
|
|
114
|
+
raise SystemExit(130) from None
|