FFT as native Polars expressions — forward/inverse FFT, magnitude, phase, and power spectrum, powered by RustFFT.
Project description
polars-rfft
FFT as native Polars expressions. Built with Rust (RustFFT) and PyO3 for zero-copy, vectorized computation over Polars DataFrames.
Install
pip install polars-rfft
Quick start
import polars as pl
from polars_rfft import rfft
df = pl.DataFrame({"signal": [1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0]})
# Forward FFT — returns struct {re, im}
df.with_columns(spectrum=rfft(pl.col("signal")).fft())
Roundtrip: FFT → IFFT
df.with_columns(
recovered=rfft(rfft(pl.col("signal")).fft()).ifft_real()
)
Magnitude, phase, power spectrum
fft_expr = rfft(pl.col("signal")).fft()
df.with_columns(
mag=rfft(fft_expr).magnitude(),
phase=rfft(fft_expr).phase(),
power=rfft(fft_expr).power_spectrum(),
)
Complex-valued input
df = pl.DataFrame({
"z": [{"re": 1.0, "im": 0.0}, {"re": 0.0, "im": 1.0},
{"re": -1.0, "im": 0.0}, {"re": 0.0, "im": -1.0}]
})
df.with_columns(spectrum=rfft(pl.col("z")).fft_complex())
API reference
Complex values are represented as struct columns with fields re (real) and im (imaginary).
| Method | Input | Output | Description |
|---|---|---|---|
fft() |
f64 | struct{re,im} | Forward FFT on real signal |
fft_complex() |
struct{re,im} | struct{re,im} | Forward FFT on complex signal |
ifft() |
struct{re,im} | struct{re,im} | Inverse FFT (normalized by 1/N) |
ifft_real() |
struct{re,im} | f64 | Inverse FFT, real part only |
magnitude() |
struct{re,im} | f64 | |
phase() |
struct{re,im} | f64 | atan2(im, re) in radians |
power_spectrum() |
struct{re,im} | f64 |
All methods are accessed via the rfft() wrapper:
from polars_rfft import rfft
rfft(pl.col("signal")).fft() # forward
rfft(pl.col("spectrum")).ifft() # inverse
rfft(pl.col("spectrum")).magnitude() # magnitude
Direct functions
For lower overhead on smaller signals, fft_direct and ifft_direct bypass the Polars expression engine and operate directly on Series:
from polars_rfft import fft_direct, ifft_direct
re, im = fft_direct(df["signal"]) # Series → (Series, Series)
re, im = ifft_direct(re, im) # (Series, Series) → (Series, Series)
Performance
Benchmarked end-to-end against numpy on signals of varying length. Median of 7 runs after warmup.
Expression API (rfft().fft())
| Signal length | Operation | polars-rfft | numpy | Speedup |
|---|---|---|---|---|
| 1,024 | fft | 0.14 ms | 0.02 ms | 0.2x |
| 4,096 | fft | 0.24 ms | 0.08 ms | 0.3x |
| 16,384 | fft | 0.66 ms | 0.99 ms | 1.5x |
| 65,536 | fft | 2.2 ms | 4.7 ms | 2.1x |
| 262,144 | fft | 10.2 ms | 22.1 ms | 2.2x |
| 1,048,576 | fft | 33.9 ms | 53.3 ms | 1.9x |
Direct API (fft_direct())
Bypasses Polars expression dispatch for ~0.1ms less overhead:
| Signal length | Operation | fft_direct | numpy | Speedup |
|---|---|---|---|---|
| 64 | fft | 0.014 ms | 0.013 ms | 0.9x |
| 256 | fft | 0.018 ms | 0.013 ms | 0.7x |
| 1,024 | fft | 0.040 ms | 0.022 ms | 0.6x |
| 4,096 | fft | 0.14 ms | 0.08 ms | 0.5x |
| 16,384 | fft | 0.64 ms | 0.99 ms | 1.5x |
| 65,536 | fft | 2.1 ms | 4.7 ms | 2.3x |
| 262,144 | fft | 9.9 ms | 22.1 ms | 2.2x |
| 1,048,576 | fft | 27.9 ms | 53.3 ms | 1.9x |
At small sizes (< 4K), numpy is faster due to its highly optimized C/Fortran backend. At 16K+ elements, RustFFT's radix algorithms dominate — up to 2.3x faster than numpy. The direct API eliminates ~0.1ms of Polars expression dispatch overhead, matching numpy at very small sizes.
Run it yourself:
pip install numpy
python benchmarks/bench_fft.py --sizes 1024 16384 262144 1048576
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_rfft-0.1.1.tar.gz.
File metadata
- Download URL: polars_rfft-0.1.1.tar.gz
- Upload date:
- Size: 30.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2239cab60cc78ae3c773cc7dfbcf73ebf43e31dff355a187e3f352d4d6aec43e
|
|
| MD5 |
49255e8586174e6c1815ad3cf5572213
|
|
| BLAKE2b-256 |
13a2b5395bed26a04b0f62e816547b088b1b41fce746558075b43f890ce3995b
|
Provenance
The following attestation bundles were made for polars_rfft-0.1.1.tar.gz:
Publisher:
release.yml on mattbuck85/polars-rfft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_rfft-0.1.1.tar.gz -
Subject digest:
2239cab60cc78ae3c773cc7dfbcf73ebf43e31dff355a187e3f352d4d6aec43e - Sigstore transparency entry: 1097419755
- Sigstore integration time:
-
Permalink:
mattbuck85/polars-rfft@a356cf989b15ade5d962e649465465c498d600de -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mattbuck85
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a356cf989b15ade5d962e649465465c498d600de -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_rfft-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: polars_rfft-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
696be55156f8ff1ea93fba6a38087b74601795505521d0f122f12ee24db7835c
|
|
| MD5 |
2b0ce1f52fb5792da802175076123f85
|
|
| BLAKE2b-256 |
5a61e2e197dd3c62a3557f943ce9c8efae555c95fae53bf623a81e25656e4268
|
Provenance
The following attestation bundles were made for polars_rfft-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on mattbuck85/polars-rfft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_rfft-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
696be55156f8ff1ea93fba6a38087b74601795505521d0f122f12ee24db7835c - Sigstore transparency entry: 1097419761
- Sigstore integration time:
-
Permalink:
mattbuck85/polars-rfft@a356cf989b15ade5d962e649465465c498d600de -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mattbuck85
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a356cf989b15ade5d962e649465465c498d600de -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_rfft-0.1.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: polars_rfft-0.1.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
342e12270cb921dd282e4a5c39b542b1ddfecef171d0deab0ef732402eeda6fa
|
|
| MD5 |
a25a72a2929f8e6ea881c6c2f2cc5a6a
|
|
| BLAKE2b-256 |
02601a18e8b478418e692858302aeed8e71e35790577393ffcb10acfd4f34a91
|
Provenance
The following attestation bundles were made for polars_rfft-0.1.1-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on mattbuck85/polars-rfft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_rfft-0.1.1-cp39-abi3-win_amd64.whl -
Subject digest:
342e12270cb921dd282e4a5c39b542b1ddfecef171d0deab0ef732402eeda6fa - Sigstore transparency entry: 1097419771
- Sigstore integration time:
-
Permalink:
mattbuck85/polars-rfft@a356cf989b15ade5d962e649465465c498d600de -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mattbuck85
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a356cf989b15ade5d962e649465465c498d600de -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
488dc9b18fbe269a9652b7793e197a45946030c13953d6b5fb11d7008d423322
|
|
| MD5 |
92aee94dd27d1ff14858354d9e36b93e
|
|
| BLAKE2b-256 |
0c0d442c72797ea001b1618ac9babf0f3530a4084c53595d9f2472bab974a6ab
|
Provenance
The following attestation bundles were made for polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on mattbuck85/polars-rfft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
488dc9b18fbe269a9652b7793e197a45946030c13953d6b5fb11d7008d423322 - Sigstore transparency entry: 1097419757
- Sigstore integration time:
-
Permalink:
mattbuck85/polars-rfft@a356cf989b15ade5d962e649465465c498d600de -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mattbuck85
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a356cf989b15ade5d962e649465465c498d600de -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caac972cc123e05296b844dda69a1adc98b52ed6fa1ada1775167c2ff6e59d68
|
|
| MD5 |
37509bb334c6247cc2ce9b153b2b866a
|
|
| BLAKE2b-256 |
e9780ab16ddf5d933ec5b71907b687726d427578e10bf0e63bd52596de218b9f
|
Provenance
The following attestation bundles were made for polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on mattbuck85/polars-rfft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_rfft-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
caac972cc123e05296b844dda69a1adc98b52ed6fa1ada1775167c2ff6e59d68 - Sigstore transparency entry: 1097419763
- Sigstore integration time:
-
Permalink:
mattbuck85/polars-rfft@a356cf989b15ade5d962e649465465c498d600de -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mattbuck85
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a356cf989b15ade5d962e649465465c498d600de -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_rfft-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_rfft-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
339fe4c77160c0bf8721192c2168a19eaf510b4d0e783876d0fa093ef99aa9d5
|
|
| MD5 |
a6be07a9649a78bc5d8945cdf5eb8043
|
|
| BLAKE2b-256 |
0b66d2ba5e5da1b5f22232aefc16f0c78232e0bf9cbbc9b08d8c05cadac215dc
|
Provenance
The following attestation bundles were made for polars_rfft-0.1.1-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on mattbuck85/polars-rfft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_rfft-0.1.1-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
339fe4c77160c0bf8721192c2168a19eaf510b4d0e783876d0fa093ef99aa9d5 - Sigstore transparency entry: 1097419768
- Sigstore integration time:
-
Permalink:
mattbuck85/polars-rfft@a356cf989b15ade5d962e649465465c498d600de -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mattbuck85
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a356cf989b15ade5d962e649465465c498d600de -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_rfft-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: polars_rfft-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05eb57b783d89d867cad0e317703cf2a6c8126f377707a38d37cd0a23ac91150
|
|
| MD5 |
2456d20364f5dd35a55ff20664275db1
|
|
| BLAKE2b-256 |
08e2fafa7511825a2de472a50216506795845fbdda89aab62612a5ebaf50656d
|
Provenance
The following attestation bundles were made for polars_rfft-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on mattbuck85/polars-rfft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_rfft-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
05eb57b783d89d867cad0e317703cf2a6c8126f377707a38d37cd0a23ac91150 - Sigstore transparency entry: 1097419766
- Sigstore integration time:
-
Permalink:
mattbuck85/polars-rfft@a356cf989b15ade5d962e649465465c498d600de -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mattbuck85
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a356cf989b15ade5d962e649465465c498d600de -
Trigger Event:
push
-
Statement type: