Skip to main content

Utilities for working with List columns in Polars

Project description

Polars List Utils (polist)

polist is a Python package that provides a set of utilities for working with List-type columns in Polars DataFrames, especially for signal processing and feature extraction.

So far these utilities comprise those that I found to be missing or lacking from the List namespace within the Polars library while I was working on a project at work that required extensive handling of signal data which I was storing in Polars DataFrames.

By providing these utilities as a Polars plugin, and thus not having to leave the Polars DataFrame for these operations, I was able to significantly speed up the processing of my data by benefiting from Polars query optimization and parallelization. So while the operations themselves are not necessarily faster than their Numpy counterparts (although they might be in some cases), the integration with Polars gave my larger processing pipeline a significant speed boost.

Status: Work-in-Progress!

Features

  • polist.apply_fft

    • Applies a Fast Fourier Transform (FFT) to a List-type column of signal data.
    • Can pre-process the signals with a windowing function (e.g. Hann, Hamming, Blackman).
    • Can pre-process the signals with a Butterworth filter (low-pass, high-pass, band-pass).
    • Can normalize the FFT amplitudes by the signal length or the window sum.
  • polist.operate_scalar_on_list

    • Applies a scalar operation of a Float-type column to each element of a List-type column.
    • This is currently not supported in Polars, see this issue.
    • Can apply the operations add, sub, mul, and div.
  • polist.interpolate_columns

    • Interpolates a new List-type column from 3 specified List-type columns.
    • Behaviour as expected from the numpy.interp function, but for Polars DataFrames.
    • Supply the x_data, y_data, and x_interp columns to obtain the y_interp column.
  • polist.aggregate_list_col_elementwise

    • Applies element-wise list-aggregations to a List-type column in a GroupBy context.
    • Currently supports sum, mean, and count.
    • This is possible using the Polars API e.g. using list.get(n) (see my SO question here), but it does not scale well as for large lists and complicated queries it can lead to a stack overflow (see this issue and many others).
  • polist.mean_of_range

    • Computes the mean of a range of y-values defined by some x-values for List-type columns.
    • This is useful for feature extraction from signals, e.g. to compute the mean of a signal in a certain time range or a spectrum in a certain frequency range.
    • This is somewhat possible using the Polars API (e.g. using list.slice and list.mean), but can get very complicated for the simple case of wanting to specify certain y-values based on a custom x-axis.
  • polist.fft_freqs

    • Computes the frequencies of the FFT bins for a given sampling rate and number of samples.
    • This function does not operate dynamically on List-type columns, use it with pl.lit.
    • This is useful for plotting the FFT spectrum in the frequency domain. Similar to the numpy.fft.fftfreq function, but in my opinion much simpler.
  • polist.fft_freqs_linspace

    • Basically a thin wrapper around something like numpy.linspace to create a linearly spaced List of values.
    • This function does not operate dynamically on List-type columns, use it with pl.lit.
    • This is useful when used together with polist.interpolate_columns.

Example: (signal) -- (hann window) -- (FFT) -- (Freq. Normalization)

DSP Example

Installation (user)

uv pip install polars-list-utils

Installation (developer)

  1. Setup Rust (i.e. install rustup)
  2. Setup Python (i.e. install uv)
  3. Setup environment and compile plugin:
uv sync --extra dev
uv run maturin develop --release
  1. (Maybe) configure Cargo to find uv's Python installs. For example:
# .cargo/config.toml
[env]
PYO3_PYTHON = "C:\\Users\\travis.hammond\\AppData\\Roaming\\uv\\python\\cpython-3.12.0-windows-x86_64-none\\python.exe"
  1. Run:
uv run ./examples/showcase_dsp.py
  1. Lint
uvx ruff check
cargo fmt

Todo

  • Add more features
  • Add more tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polars_list_utils-0.14.0.tar.gz (277.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

polars_list_utils-0.14.0-cp38-abi3-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_list_utils-0.14.0-cp38-abi3-win32.whl (3.8 MB view details)

Uploaded CPython 3.8+Windows x86

polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_i686.whl (5.2 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_armv7l.whl (5.0 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (5.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (4.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.6 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

polars_list_utils-0.14.0-cp38-abi3-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_list_utils-0.14.0-cp38-abi3-macosx_10_12_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file polars_list_utils-0.14.0.tar.gz.

File metadata

  • Download URL: polars_list_utils-0.14.0.tar.gz
  • Upload date:
  • Size: 277.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for polars_list_utils-0.14.0.tar.gz
Algorithm Hash digest
SHA256 b7537cebc7265c341d5c76e9c96c00210f7a926efc8e8766c2cadf3ccdbed86e
MD5 ffcbdfd346461d959e70279e1464ba04
BLAKE2b-256 0b7df676139a37c0e302f8c6f9d9c9a6ef0b3597e814186726693286d8fdab4f

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6ad943580e328280345c2edcbff048085129793e96d4f653ab38ae26a9466240
MD5 400522661e3c9911d298737c1f04f795
BLAKE2b-256 16ced2e843ded7738f04536de955cb3ea2e9b744bdcd4c07d59251020c4994f7

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-win32.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 a0c33f0fde48e4e3749c1442503f484ebad94f84290e7052ea64548a4b8b7c0c
MD5 5710c1b63b2a98a848a8b7019858fb92
BLAKE2b-256 c5ba62a6814411dfcdb75d2f5bde77ba6d7906691179fbdacc24394cf0d8458e

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 189fb75a89e817d2e692bf17bd1418e05a55ca80683988651b1afd349f207def
MD5 58a31f2ebba4b6c2190f89547c70c02c
BLAKE2b-256 7d6ea6c14dea5705ef6e5d30d999c148b5ad1191dae079c3ce2323cb3b56b7a4

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 0d4a5af7bec3e4e5b37a02521fb7b0cdc1400e9a49b7d8e3430c35c3420b808d
MD5 b1dd8f3ca90d89b845a662646a060e59
BLAKE2b-256 e94dd8696cdb76e54277d21de902309ff0dba748bfd6a3dc72086742c1224d34

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 bfee8767d5851725c6154c6ea44e9663b451a1a9c4858c618654fd36dcb57ddf
MD5 830fec05e7585afff03266afca5752ab
BLAKE2b-256 3fb2d6e10ff5f80c25dd47682cb647e5f9da9b5a653af324090cdc59b693cbf3

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7998e4d96f62b1eeabf6d5ed0bf6cc67d7c87a65d6129a082e57c48fc521040c
MD5 2f3cd5ace5472930c67592b8185efc79
BLAKE2b-256 8ed9c4cfa65d6f74df80869bc3eb622d53e44db75f154a50b2567f95f0932a03

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da94bb2b0fbadf2246704f8020605d1b6ce9a9db3a526a4f80f4651d47068c32
MD5 fc7e4041cd41b2bd396f98c11c5083d7
BLAKE2b-256 63e0809bf7062de477284feb5657fce03470bb48fc87addfb808baa4671c5e24

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 0d0daa04a96115c6b3b53536f2fce278b208c64c83b72afd2ae9738fcb1446a2
MD5 8e03e249ca376d5e8c078aa71f8374ce
BLAKE2b-256 0a342dfb36557e5e077a7f5dc04f8f252cd8429a61083f21e95fee305ad8178f

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d365c629f08a44290c8dd715bdb2e855f1a3b3a32beb2a2338324856b4afd562
MD5 ccc1898ad160a39648772eced3caa8f1
BLAKE2b-256 ea94e6c48dc3d0ea50c0700b543af5309d5b9d6b50f2030d40440ff6f6b42b51

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 64199fceb8bc40f1ca7b8c6db08b515aa376e29b86d77019087599b6af81c974
MD5 ffc06f90f3fa8ffe81937fc4211a7671
BLAKE2b-256 81188392e828ed90fa4476dfbb818e5c208dff68a7f530e64674474e3e2f72c1

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d9c592616e4a538a0452f3fde70b38b852ce3f5459fb14c2c74bf6bcd4d2fd9
MD5 c76746a1b804474143cf76d900b31340
BLAKE2b-256 77fb38ebae90f4ecd4a7a6da9e2eaeddea5f8c4e541144bf07c8eb740a978463

See more details on using hashes here.

File details

Details for the file polars_list_utils-0.14.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_list_utils-0.14.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 329ff553a933d3aaa8e9170955205f23ff67436f6732c7e73eb09bae756b71b5
MD5 389ae872203aa60709918b85472c4c1d
BLAKE2b-256 62ff01105a1879c0f3d1e54d287813552121ffcf66d59fe86a1445477816e156

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page