pcodec

raw JSON →
1.0.1 verified Fri May 01 auth: no python

Good compression for numerical sequences. Current version 1.0.1, released periodically.

pip install pcodec
error ImportError: cannot import name 'compress' from 'pcodec'
cause Older versions of pcodec had different public API or the module is not installed correctly.
fix
Ensure pcodec >= 1.0.0 is installed: pip install --upgrade pcodec
error TypeError: compress() got an unexpected keyword argument 'nums'
cause In v1.0.0, 'nums' argument was renamed to 'src'.
fix
Use compress(src=your_array) instead of compress(nums=your_array).
breaking In v1.0.0, function arguments were renamed: 'nums' became 'src', and 'none' delta encoding became 'no_op'.
fix Update calls: compress(src=...) and use delta_encoding='no_op' instead of 'none'.
breaking In v1.0.0, simple_compress_into now accepts any Write impl (Rust change); Python API may have changed signature.
fix Check pcodec documentation for current function signatures.
gotcha Compression and decompression require numpy arrays; other iterables may not work.
fix Convert your data to a numpy array with the correct dtype before calling compress.

Compress and decompress a numpy array of float64.

from pcodec import compress, decompress
import numpy as np

data = np.array([1.0, 2.5, 3.2, 4.8, 5.1], dtype=np.float64)
compressed = compress(data)
decompressed = decompress(compressed, dtype=np.float64)
print(decompressed)