Metadata-Version: 2.4
Name: dsdiff
Version: 0.2.0
Summary: Diff two dataset files: schema changes plus column-level distribution drift.
Project-URL: Homepage, https://github.com/jmweb-org/dsdiff
Project-URL: Repository, https://github.com/jmweb-org/dsdiff
Project-URL: Issues, https://github.com/jmweb-org/dsdiff/issues
Author: José del Río
License: MIT License
        
        Copyright (c) 2026 José del Río
        
        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.
License-File: LICENSE
Keywords: cli,data,dataset,diff,drift,mlops,psi,schema
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24
Requires-Dist: polars>=1.0
Requires-Dist: rich>=13.0
Requires-Dist: typer>=0.12
Description-Content-Type: text/markdown

# dsdiff

[![CI](https://github.com/jmweb-org/dsdiff/actions/workflows/ci.yml/badge.svg)](https://github.com/jmweb-org/dsdiff/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/dsdiff.svg)](https://pypi.org/project/dsdiff/)
[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

A git-style diff between two dataset files: schema changes and column-level
distribution drift, with a CI gate.

When a dataset is regenerated, columns quietly get renamed, retyped, gain
nulls, or shift distribution, and the pipeline keeps running while the model
degrades. There is no quick "git diff for data" a reviewer can read on a pull
request. `dsdiff` is that: point it at two files and it reports what changed,
ranked by how much it should worry you.

```console
$ dsdiff diff yesterday.parquet today.parquet
severity  column      change         detail
high      income      drift          PSI 0.412
high      signup_date column_added   new column
medium    age          null_rate      null rate 0.0% -> 7.3%
low       country      cardinality    distinct values 41 -> 44
```

## Install

```console
$ pip install dsdiff                 # from PyPI, once released
$ pip install git+https://github.com/jmweb-org/dsdiff   # latest, available now
```

Reads CSV, Parquet and JSON Lines through polars. No services, no schema files
to author.

## Usage

```console
$ dsdiff diff a.csv b.csv            # human-readable table
$ dsdiff diff a.csv b.csv --json     # machine-readable findings
$ dsdiff diff a.csv b.csv --markdown # a table to paste into a PR
$ dsdiff diff a.csv b.csv --check    # exit non-zero on a high-severity change
```

### Commit a baseline

Profile a dataset once and compare future data against the saved profile,
without re-reading the original file:

```console
$ dsdiff profile reference.parquet -o baseline.json
$ dsdiff diff baseline.json new_batch.parquet --check
```

The baseline stores the bin edges, so drift on `new_batch` is measured against
exactly the same buckets as the reference.

### In CI

```yaml
- run: dsdiff diff baseline.json data/current.parquet --check
```

## What it checks

- **Schema**: columns added, removed, or retyped (all high severity).
- **Nulls**: a jump in the null rate of a shared column.
- **Cardinality**: a categorical column gaining or losing distinct values.
- **Distribution drift**: the population stability index (PSI) per column,
  numeric columns binned by quantiles and categoricals by frequency.

## Severity and the PSI scale

PSI is the standard tabular drift measure. The conventional reading is used
here: below 0.1 is **low** (no meaningful shift), 0.1 to 0.25 is **medium**,
and 0.25 or above is **high**. Schema and type changes are always high. By
default `--check` fails only on high-severity findings; pass `--fail-on medium`
to tighten the gate.

## Exit codes

| Code | Meaning |
| --- | --- |
| 0 | Ran; no blocking finding (or `--check` not set) |
| 1 | `--check` found a finding at or above the fail threshold |
| 2 | A file was missing or in an unsupported format |

## License

MIT. See [LICENSE](LICENSE).
