Registry / data / tsdownsample

tsdownsample

JSON →
library0.1.4.1pypypi✓ verified 35d ago

tsdownsample is an extremely fast Python library for time series downsampling, leveraging Rust for its core implementation. It utilizes SIMD instructions and multithreading (via Rayon in Rust) to provide highly optimized, memory-efficient, and flexible algorithms for visualization and analysis of large time series datasets. The library is actively maintained, with its current version being 0.1.4.1.

datadatabase
Install & Compatibility
Where this runs
tested against v0.1.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.244s · 99.5MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.8s · import 0.265s · 95MB
99MB installed
● package 99MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from tsdownsample import MinMaxLTTBDownsampler
from tsdownsample import LTTBDownsampler

And other downsamplers like EveryNthDownsampler, M4Downsampler, and their NaN-handling variants (e.g., NaNMinMaxDownsampler).

from tsdownsample import MinMaxDownsampler

This quickstart demonstrates how to use `MinMaxLTTBDownsampler` to reduce a large time series dataset to a smaller, representative subset of points for visualization or analysis. It shows how to initialize a downsampler and use the `downsample` method with both `x` (optional time/index) and `y` (values) arrays, specifying the desired output size `n_out` and enabling parallel processing.

import numpy as np from tsdownsample import MinMaxLTTBDownsampler # Create a time series with x and y values x = np.arange(10_000_000, dtype=np.float64) y = np.random.randn(10_000_000).astype(np.float64) # Initialize the downsampler downsampler = MinMaxLTTBDownsampler() # Downsample the time series to 1000 points # The 'parallel=True' argument enables multi-threading for performance. # The 'n_out' argument is mandatory. selected_indices = downsampler.downsample(x, y, n_out=1000, parallel=True) # Retrieve the downsampled data points x_downsampled = x[selected_indices] y_downsampled = y[selected_indices] print(f"Original data points: {len(x)}") print(f"Downsampled data points: {len(x_downsampled)}") print(f"First 5 downsampled x: {x_downsampled[:5]}") print(f"First 5 downsampled y: {y_downsampled[:5]}")
Debug
Known footguns
gotchaThe `x` (index) data must be non-strictly monotonic increasing (i.e., sorted) and should not contain NaN values. If not provided, it's assumed to be equally sampled without gaps.
gotchaWhen `x` data contains gaps (i.e., non-equidistant sampling), the number of returned downsampled indices might be less than the specified `n_out`. This is because no data points can be selected for empty bins.
gotchaTo leverage multi-threading for performance, the `parallel=True` argument must be explicitly passed to the `downsample` method. The maximum number of threads can be configured via the `TSDOWNSAMPLE_MAX_THREADS` environment variable.
gotchaA precision error in the `sequential_add_mul` update logic was fixed in version 0.1.4.1. While a bug fix, users relying on the previous (incorrect) numerical behavior might observe different outputs after upgrading.
gotchaThe `downsample` method's signature is `downsample(x, y, n_out=..., **kwargs)`. `x` and `y` are positional arguments, while `n_out` is a mandatory keyword argument.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
14 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
googlebot
1
chatgpt-user
1
Resources