Metadata-Version: 2.4
Name: splitcheck
Version: 0.2.0
Summary: Detect row overlap and leakage between dataset splits.
Project-URL: Homepage, https://github.com/jmweb-org/splitcheck
Project-URL: Repository, https://github.com/jmweb-org/splitcheck
Project-URL: Issues, https://github.com/jmweb-org/splitcheck/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,data-leakage,deduplication,mlops,train-test-split
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: polars>=1.0
Requires-Dist: rich>=13.0
Requires-Dist: typer>=0.12
Description-Content-Type: text/markdown

# splitcheck

[![CI](https://github.com/jmweb-org/splitcheck/actions/workflows/ci.yml/badge.svg)](https://github.com/jmweb-org/splitcheck/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/splitcheck.svg)](https://pypi.org/project/splitcheck/)
[![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)

Detect rows that leak between dataset splits, and fail CI when they do.

A row that appears in both train and test inflates every metric and is easy to
introduce: a careless `concat`, a re-export, a duplicated record. `splitcheck`
compares your splits and reports how much of one appears in another, both as
exact matches and after normalization, so cosmetic differences do not hide a
leak.

```console
$ splitcheck check train.csv test.csv --on text --max-leakage 0.0
target  in source  exact  normalized  leakage
test    train          1           3     2.1%
splitcheck: worst leakage 2.1%
```

## Install

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

Reads CSV, Parquet, JSON Lines, and plain text (one row per line) through polars.

## Usage

```console
$ splitcheck check train.csv test.csv                 # compare whole rows
$ splitcheck check train.csv val.csv test.csv         # all pairs at once
$ splitcheck check train.csv test.csv --on text       # compare one column
$ splitcheck check train.csv test.csv --json          # machine-readable
$ splitcheck check train.csv test.csv --max-leakage 0.01   # allow 1%
$ splitcheck check train.csv test.csv --no-check      # report without failing
```

By default any leakage fails the command (`--max-leakage 0.0`). Raise the limit
to tolerate a known, small overlap.

### In CI

```yaml
- run: splitcheck check data/train.parquet data/test.parquet --on text
```

## How matching works

Each row is reduced to a string: a single column with `--on`, or the whole row
joined tab-separated. Two matches are reported:

- **exact**: identical strings.
- **normalized**: equal after case folding, punctuation removal and whitespace
  collapsing, which catches the same example re-saved with cosmetic changes.

Leakage is the fraction of the **target** split (for example test) whose rows
also appear in a **source** split (for example train). Pairs are checked in both
directions and sorted worst-first.

## Exit codes

| Code | Meaning |
| --- | --- |
| 0 | Checked; leakage within the limit (or `--no-check`) |
| 1 | Leakage exceeded `--max-leakage` |
| 2 | Fewer than two files, or a file was missing or unsupported |

## Scope

Matching is exact or normalized-exact, not fuzzy. Near-duplicates that differ in
wording (paraphrases) are not caught; see the issues for planned MinHash-based
fuzzy matching.

## License

MIT. See [LICENSE](LICENSE).
