Skip to main content

TDigest-rs

Simple Python package to compute TDigests, implemented in Rust.

Introduction

TDigest-rs is a Python library with a Rust backend that implements the T-Digest algorithm, enhancing the estimation of quantiles in streaming data. For an in-depth exploration of the T-Digest algorithm, refer to Ted Dunning and Otmar Ertl's paper and the G-Research blog post.

Usage

pip install tdigest-rs

The library contains a single TDigest class.

Creating a TDigest object

from tdigest_rs import TDigest

# Fit a TDigest from a numpy array (float32 or float64)
arr = np.random.randn(1000)
tdigest = TDigest.from_array(arr=arr, delta=100.0)  # delta is optional and defaults to 300.0
print(tdigest.means, tdigest.weights)

# Create directly from means and weights arrays
vals = np.random.randn(1000).astype(np.float32)
weights = np.ones(1000).astype(np.uint32)
tdigest = TDigest.from_means_weights(arr=vals, weights=weights)

Computing quantiles

# Compute a quantile
tdigest.quantile(0.1)

# Compute median
tdigest.median()

# Compute trimmed mean
tdigest.trimmed_mean(lower=0.05, upper=0.95)

Merging TDigests

arr1 = np.random.randn(1000)
arr2 = np.ones(1000)
digest1 = TDigest.from_array(arr=arr1)
digest2 = TDigest.from_array(arr=arr2)

merged_digest = digest1.merge(digest2, delta=100.0)  # delta again defaults to 300.0

Serialising TDigests

The TDigest object can be converted to a dictionary and JSON-serialised and is also pickleable.

# Convert and load to/from a python dict
d = tdigest.to_dict()
loaded_digest = TDigest.from_dict(d)

# Pickle a digest
import pickle

pickle.dumps(tdigest)

Development workflow

pip install hatch

cd bindings/python

# Run linters
hatch run dev:lint

# Run tests
hatch run dev:test

# Run benchmark
hatch run dev:benchmark

# Format code
hatch run dev:format

Contributing

Please read our contributing guide and code of conduct if you'd like to contribute to the project.

Community Guidelines

Please read our code of conduct before participating in or contributing to this project.

Security

Please see our security policy for details on reporting security vulnerabilities.

License

TDigest-rs is licensed under the Apache Software License 2.0 (Apache-2.0)

Metadata

Release files for tdigest-rs 0.1.0

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

Built distributions (wheels)

Table of built distributions (wheels) for tdigest-rs 0.1.0
File
tdigest_rs-0.1.0-cp37-abi3-win_amd64.whl CPython 3.7 abi3 Windows x86-64 Details
tdigest_rs-0.1.0-cp37-abi3-musllinux_1_2_x86_64.whl CPython 3.7 abi3 Linux musl 1.2+ x86-64 Details
tdigest_rs-0.1.0-cp37-abi3-musllinux_1_2_aarch64.whl CPython 3.7 abi3 Linux musl 1.2+ ARM64 Details
tdigest_rs-0.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 abi3 Linux glibc 2.17+ x86-64 Details
tdigest_rs-0.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.7 abi3 Linux glibc 2.17+ ARM64 Details
tdigest_rs-0.1.0-cp37-abi3-macosx_11_0_arm64.whl CPython 3.7 abi3 macOS 11.0+ ARM64 Details
tdigest_rs-0.1.0-cp37-abi3-macosx_10_12_x86_64.whl CPython 3.7 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.4 MB

Release files / tdigest_rs-0.1.0-cp37-abi3-win_amd64.whl

Download URL tdigest_rs-0.1.0-cp37-abi3-win_amd64.whl
Size 175.5 kB
Tags CPython 3.7 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7c47fec4aa8f479318e13f25ecfa8f89f2c20cb3700697d87fcc4633ff704694
BLAKE2b-256 checksum
How to use checksums
abe3b889f648baebb9ee7d1129709a8c70059ec3a47a2a80ac5a404c4f1b4e45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tdigest_rs-0.1.0-cp37-abi3-musllinux_1_2_x86_64.whl

Download URL tdigest_rs-0.1.0-cp37-abi3-musllinux_1_2_x86_64.whl
Size 1.2 MB
Tags CPython 3.7 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
aee1c3f1fa2b6969494b7b11d41b3c6b94240748e541be88746d87eff54e8256
BLAKE2b-256 checksum
How to use checksums
66f006d468b1d518de252d10824c52c16c7cce7621db80323a2624b5338715fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tdigest_rs-0.1.0-cp37-abi3-musllinux_1_2_aarch64.whl

Download URL tdigest_rs-0.1.0-cp37-abi3-musllinux_1_2_aarch64.whl
Size 1.2 MB
Tags CPython 3.7 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
3fff29326b67cec8e35130e1d8dbab104eea677492ca3e954e9a0676e21db214
BLAKE2b-256 checksum
How to use checksums
d2b8751dc806f20388c0ff28de7283b3a810d6d606269c47864b9d244d8079a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tdigest_rs-0.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL tdigest_rs-0.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.7 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
62ee8d5a01226d020a2ab11a956292c38beab3f34d2d9fa7a8fca22c3e5d4bbf
BLAKE2b-256 checksum
How to use checksums
893bfaabc31e51eeae07efe1ad55d1e92daa495a6dddea99371a6896b644e93a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tdigest_rs-0.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL tdigest_rs-0.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.1 MB
Tags CPython 3.7 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
b4174b74aecc1d791e4f0007bcc043c75d7ec46f43bf8fbc6f4a4340e46a8028
BLAKE2b-256 checksum
How to use checksums
0f7c5e48f9b60eca4f2888b4826f365d6af31ca9846f5e7875ec05ca1051bc5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tdigest_rs-0.1.0-cp37-abi3-macosx_11_0_arm64.whl

Download URL tdigest_rs-0.1.0-cp37-abi3-macosx_11_0_arm64.whl
Size 287.3 kB
Tags CPython 3.7 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c4ca4f538c3fa204da2580f21f4258f53a16914e7877d6a07d81d809c74529a9
BLAKE2b-256 checksum
How to use checksums
788b3275dabf1d16409eaa2dc98ef4c9e8eda00a7df2e8e3adc8f612815d2ffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tdigest_rs-0.1.0-cp37-abi3-macosx_10_12_x86_64.whl

Download URL tdigest_rs-0.1.0-cp37-abi3-macosx_10_12_x86_64.whl
Size 291.9 kB
Tags CPython 3.7 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
417d452ac5f86a8eb37c1671b99780b7186830588f17d675bca5f254880c5ed0
BLAKE2b-256 checksum
How to use checksums
b3e212b15d07cf431673f52356a46d1279839cfccf10d897f99b5ac1cdfd9d07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

7 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