Skip to main content

🔒 safesplit

Leakage-safe train/test splits — group-aware, time-aware, de-duplicated.

sklearn.train_test_split shuffles rows at random. For a lot of real data that quietly leaks: the same patient lands on both sides, a time series trains on its own future, or duplicate rows sit in train and test. Your score looks great and isn't real.

safesplit gives you one honest split:

pip install safesplit
from safesplit import safe_split

# a group is never on both sides
train, test = safe_split(df, group_col="patient_id")

# train on the past, test on the future
train, test = safe_split(df, time_col="date")

# keep near-homologous protein/DNA sequences together
train, test = safe_split(df, seq_col="sequence")

# plain random split, but exact duplicates are dropped first
train, test = safe_split(df, test_size=0.2)

What it does

You pass What you get
group_col every group (patient / user / device) stays entirely on one side
seq_col protein/DNA sequences that are similar stay on one side (homology-safe)
time_col a chronological split — train is the past, test is the future
dedupe=True (default) exact duplicate rows are removed before splitting
nothing extra a reproducible random split

The companion to LeakHound

safesplit prevents the leaks that LeakHound detects. Split with one, verify with the other:

from safesplit import safe_split
from leakhound import audit           # pip install leakhound-ml

train, test = safe_split(df, group_col="patient_id")
assert audit(train, test, group_col="patient_id").clean

License

GNU AGPL-3.0-or-later © 2026 Joel Gomes. A commercial license is available if the copyleft terms don't fit your use — open an issue.

Metadata

Release files for safesplit 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for safesplit 0.2.0
File Size Uploaded
safesplit-0.2.0.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for safesplit 0.2.0
File Interpreter ABI Platform
safesplit-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.6 kB

Release files / safesplit-0.2.0.tar.gz

Download URL safesplit-0.2.0.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
97202cb763fbf70efb3fad8e855c798d2c45a9d7f53f7ca6ec9b73f284711f27
BLAKE2b-256 checksum
How to use checksums
fc882c06f95c6b1b9670719416d163b739ab65dd793d68fbf5163bbcf47b8204
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / safesplit-0.2.0-py3-none-any.whl

Download URL safesplit-0.2.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fcf916e3f1d325525aa5238f7c2614620f9216e6a7e7470cea60f7f7ae21d33
BLAKE2b-256 checksum
How to use checksums
9073e901fcfc33f0b8f89023165a3d1ff9b410b0254d5401fa302477d2880c08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.3.0

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page