Polars plugin expressions and stream processors for flux-controlled dynamic windows.
Project description
polars-fluxbar
polars-fluxbar 是一个面向 Polars 的 Python/Rust 扩展,提供由“通量”、
局部极值数量或非零条件值数量控制的动态窗口统计能力,同时包含可在 Python
中逐行调用的流式处理器。
功能特性
dynamic_window_stat/dynamic_window_stat_pipe:按累计条件值控制窗口长度。extrema_window_stat/extrema_window_stat_pipe:按局部极值数量控制窗口长度。nonzero_window_stat/nonzero_window_stat_pipe:按cond != 0的数量控制窗口长度,零值行保留在窗口内参与目标值统计。dynamic_window/extrema_window/nonzero_window及对应*_pipe:只返回目标窗口 list 列。*_window_stat_pipe支持多目标列选择器,如pl.col(["close", "open"]),多目标输出按{prefix}{target}_{stat}命名。DynamicWindowFilter/ExtremaWindowFilter/NonZeroWindowFilter:适合流式、逐 tick 或 REPL 调试的 Python 调用接口。Stat:统一描述avg、sum、max、min、quantile、rank、argmax、argmin等统计项。distribution_sample:按行生成确定性的分布采样结果,支持静态参数和来自列的参数。
安装
开发阶段建议先构建本地扩展:
uv sync --group dev
uv run maturin develop --release
完成构建后即可在当前虚拟环境中导入:
import polars as pl
from polars_fluxbar import Stat
from polars_fluxbar.expr import dynamic_window_stat_pipe
df = pl.DataFrame(
{
"volume": [1.0, 2.0, 1.0, 3.0],
"close": [10.0, 11.0, 9.5, 12.0],
"open": [9.8, 10.2, 10.7, 10.0],
}
)
out = (
df.lazy()
.pipe(
dynamic_window_stat_pipe,
period=3.0,
stats=[Stat.avg(), Stat.max(), "count"],
cond_col="volume",
target_col=pl.col(["close", "open"]),
prefix="dyn_",
)
.collect()
)
print(out)
单目标调用保持旧命名,如 dyn_avg;多目标调用会生成 dyn_close_avg、
dyn_open_avg 等列。若只需要窗口内目标列表,可使用 dynamic_window_pipe、
extrema_window_pipe 或 nonzero_window_pipe。
更多可直接运行的示例见 examples/demo_fluxbar.py。
开发
常用检查命令:
uv run maturin develop --release
uv run pytest tests
cargo clippy --all-targets --all-features
构建发布产物:
uv run maturin build --release --sdist --compatibility pypi
发布脚本
仓库提供 scripts/gitee_release.py,用于构建/发布 PyPI 包,并将产物镜像到 Gitee Release。
发布前需要配置 .env 或环境变量,至少包含:
PYPI_API_TOKENGITEE_TOKEN
脚本只要求这两个变量存在,可以通过 .env 或执行前指定。子进程仍会继承完整环境,
以便 MSVC、Rust、uv 等构建工具正常工作。项目版本、Gitee 仓库地址、tag、release
名称和目标提交会从 pyproject.toml、Cargo.toml 与 git remote 中自动推导。
许可
本项目使用 MIT License,详见 LICENSE。
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
Built Distribution
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_fluxbar-0.2.0.tar.gz.
File metadata
- Download URL: polars_fluxbar-0.2.0.tar.gz
- Upload date:
- Size: 53.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebd7da8b0b90a17fcb07ae6a253a89e841bf855b9dd70a651072140544b66677
|
|
| MD5 |
e259baf80d4b9fc13b9a3d778a4b87dc
|
|
| BLAKE2b-256 |
d26ce711ee4be5188f18bb7a6822188ff8c6ab00ffe22fc0ba18f49f8a02ff57
|
File details
Details for the file polars_fluxbar-0.2.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: polars_fluxbar-0.2.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c4f3241029c6aa59b7a5b260e89a1be990fab082372607cbc21c3ed4785e18c
|
|
| MD5 |
748dc3980b1ac722cafbeb86e3ed0170
|
|
| BLAKE2b-256 |
60b447a111febd2ae001ffd46d1ca027b37562757db51db5841b1bbf10e7f668
|