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")

# 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
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.1.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.1.0
File Size Uploaded
safesplit-0.1.0.tar.gz 15.1 kB Details

Built distribution (wheel)

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

Total release size: 30.2 kB

Release files / safesplit-0.1.0.tar.gz

Download URL safesplit-0.1.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9a5e2239495625c5bc4840884647198bd1c3a5686aea0216d71b253da6a6b1f7
BLAKE2b-256 checksum
How to use checksums
618fc9206ec9e52dc42c7bb69ea24c4a179139ff98c24ec30d2cc67dadd74187
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.1.0-py3-none-any.whl

Download URL safesplit-0.1.0-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe0ae7f2cc75bb8ec8ef6e5439b56152f6a584827ce1fda70034c62d09340657
BLAKE2b-256 checksum
How to use checksums
33d22da2c35991eb7ccf47cc3a6faa2146034064513fa58bfdf54fc832a965ee
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

0.2.0

2 release files

This release

0.1.0 This release

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