polars-array-algorithms 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polars_array_algorithms-0.1.0/.github/copilot-instructions.md +93 -0
- polars_array_algorithms-0.1.0/.github/workflows/publish_to_pypi.yml +72 -0
- polars_array_algorithms-0.1.0/.gitignore +140 -0
- polars_array_algorithms-0.1.0/Cargo.lock +3436 -0
- polars_array_algorithms-0.1.0/Cargo.toml +24 -0
- polars_array_algorithms-0.1.0/LICENSE +21 -0
- polars_array_algorithms-0.1.0/Makefile +28 -0
- polars_array_algorithms-0.1.0/PKG-INFO +8 -0
- polars_array_algorithms-0.1.0/README.md +164 -0
- polars_array_algorithms-0.1.0/polars_array_algorithms/__init__.py +82 -0
- polars_array_algorithms-0.1.0/polars_array_algorithms/_internal.pyi +3 -0
- polars_array_algorithms-0.1.0/polars_array_algorithms/typing.py +17 -0
- polars_array_algorithms-0.1.0/pyproject.toml +20 -0
- polars_array_algorithms-0.1.0/requirements.txt +5 -0
- polars_array_algorithms-0.1.0/rust-toolchain.toml +2 -0
- polars_array_algorithms-0.1.0/rustfmt.toml +3 -0
- polars_array_algorithms-0.1.0/src/lib.rs +19 -0
- polars_array_algorithms-0.1.0/src/sweep_line.rs +199 -0
- polars_array_algorithms-0.1.0/tests/test_sweep_line_assignment.py +88 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Polars Array Algorithms - Copilot Instructions
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
This is a Rust + Python hybrid project implementing additional array algorithms for the Polars library. The project uses:
|
|
5
|
+
- **Rust**: Core algorithm implementations with PyO3 bindings via `pyo3-polars`
|
|
6
|
+
- **Python**: Plugin registration, type stubs, and tests using Pytest
|
|
7
|
+
- **Build System**: Maturin for compiling Rust to Python extension modules
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
### Rust Side (`src/`)
|
|
12
|
+
- **lib.rs**: Module root and PyO3 module definition with `#[pymodule]` decorator
|
|
13
|
+
- **expressions.rs**: Custom expression implementations using `#[polars_expr]` macro
|
|
14
|
+
- Functions must accept `&[Series]` and return `PolarsResult<Series>`
|
|
15
|
+
- Use `apply_into_string_amortized()` for string operations and similar chunked array methods for performance
|
|
16
|
+
|
|
17
|
+
### Python Side (`polars_array_algorithms/`)
|
|
18
|
+
- **__init__.py**: Plugin registration via `register_plugin_function()`
|
|
19
|
+
- **_internal.pyi**: Type stubs for Rust-compiled module
|
|
20
|
+
- **typing.py**: Custom type definitions like `IntoExprColumn`
|
|
21
|
+
|
|
22
|
+
### Testing & CI
|
|
23
|
+
- **tests/**: Pytest-based tests for all expressions
|
|
24
|
+
- **Makefile**: Build, install, and testing commands
|
|
25
|
+
- Pre-commit checks: `cargo fmt`, `cargo clippy`, `ruff`, `mypy`
|
|
26
|
+
|
|
27
|
+
## Development Guidelines
|
|
28
|
+
|
|
29
|
+
### Adding New Expressions
|
|
30
|
+
1. **Rust Implementation** (`src/expressions.rs`):
|
|
31
|
+
- Use `#[polars_expr(output_type=<Type>)]` macro
|
|
32
|
+
- Handle chunked arrays efficiently (avoid unnecessary allocations)
|
|
33
|
+
- Use Polars' built-in methods for array operations
|
|
34
|
+
|
|
35
|
+
2. **Python Wrapper** (`polars_array_algorithms/__init__.py`):
|
|
36
|
+
- Create a function that calls `register_plugin_function()`
|
|
37
|
+
- Set `is_elementwise=True` for element-wise operations
|
|
38
|
+
- Update type hints using `IntoExprColumn`
|
|
39
|
+
|
|
40
|
+
3. **Type Stub** (`polars_array_algorithms/_internal.pyi`):
|
|
41
|
+
- Add function signature for the compiled Rust function
|
|
42
|
+
|
|
43
|
+
4. **Tests** (`tests/`):
|
|
44
|
+
- Create test file following `test_<expression_name>.py` pattern
|
|
45
|
+
- Use Pytest with Polars DataFrames for validation
|
|
46
|
+
|
|
47
|
+
### Code Quality
|
|
48
|
+
- Run `make pre-commit` before committing
|
|
49
|
+
- Rust formatting: `cargo +nightly fmt --all`
|
|
50
|
+
- Linting: `cargo clippy --all-features`
|
|
51
|
+
- Python formatting: `ruff` (enforces consistent style)
|
|
52
|
+
- Type checking: `mypy` (strict typing for Python)
|
|
53
|
+
|
|
54
|
+
### Building & Running
|
|
55
|
+
- **Development**: `make install` (builds with debug symbols)
|
|
56
|
+
- **Release**: `make install-release` (optimized build)
|
|
57
|
+
- **Tests**: `make test` (runs all Pytest tests)
|
|
58
|
+
- **Full run**: `make run` or `make run-release`
|
|
59
|
+
|
|
60
|
+
## Important Constraints
|
|
61
|
+
|
|
62
|
+
### 🚫 STRICTLY DO NOT CREATE NEW FILES
|
|
63
|
+
- **Do NOT create new files or directories unless explicitly prompted by the user**
|
|
64
|
+
- This includes:
|
|
65
|
+
- Documentation files (Markdown, RST, etc.)
|
|
66
|
+
- Configuration files
|
|
67
|
+
- Test files
|
|
68
|
+
- Source files
|
|
69
|
+
- Any other files not explicitly requested
|
|
70
|
+
- Only modify existing files or create files when the user specifically asks for it
|
|
71
|
+
|
|
72
|
+
## Best Practices
|
|
73
|
+
|
|
74
|
+
- Keep algorithm implementations focused and modular
|
|
75
|
+
- Leverage Polars' chunked array API for performance
|
|
76
|
+
- Add comprehensive tests for edge cases
|
|
77
|
+
- Use descriptive variable names and comments for complex logic
|
|
78
|
+
- Document performance considerations for algorithms
|
|
79
|
+
- Maintain compatibility with Polars >= 0.52.0 and Python >= 3.8
|
|
80
|
+
|
|
81
|
+
## Common Tasks
|
|
82
|
+
|
|
83
|
+
| Task | Command |
|
|
84
|
+
|------|---------|
|
|
85
|
+
| Setup environment | `make venv && make install` |
|
|
86
|
+
| Run all checks | `make pre-commit` |
|
|
87
|
+
| Run tests | `make test` |
|
|
88
|
+
| Rebuild after changes | `make install` |
|
|
89
|
+
| Release build | `make install-release && make run-release` |
|
|
90
|
+
|
|
91
|
+
## Dependencies
|
|
92
|
+
- **Rust**: pyo3 (0.26.0), pyo3-polars (0.25.0), polars (0.52.0)
|
|
93
|
+
- **Python**: polars, maturin, pytest, ruff, mypy
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
tags:
|
|
8
|
+
- "*"
|
|
9
|
+
pull_request:
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
env:
|
|
16
|
+
RUSTFLAGS: "-Dwarnings"
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
build:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: 3.x
|
|
26
|
+
- uses: PyO3/maturin-action@v1
|
|
27
|
+
with:
|
|
28
|
+
target: x86_64
|
|
29
|
+
args: --release --out dist
|
|
30
|
+
sccache: "true"
|
|
31
|
+
manylinux: auto
|
|
32
|
+
- uses: actions/upload-artifact@v4
|
|
33
|
+
with:
|
|
34
|
+
name: wheels-linux-x86_64
|
|
35
|
+
path: dist
|
|
36
|
+
|
|
37
|
+
sdist:
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- uses: PyO3/maturin-action@v1
|
|
42
|
+
with:
|
|
43
|
+
command: sdist
|
|
44
|
+
args: --out dist
|
|
45
|
+
- uses: actions/upload-artifact@v4
|
|
46
|
+
with:
|
|
47
|
+
name: wheels-sdist
|
|
48
|
+
path: dist
|
|
49
|
+
|
|
50
|
+
publish:
|
|
51
|
+
name: Publish to PyPI
|
|
52
|
+
runs-on: ubuntu-latest
|
|
53
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
54
|
+
needs: [build, sdist]
|
|
55
|
+
environment: pypi
|
|
56
|
+
permissions:
|
|
57
|
+
id-token: write
|
|
58
|
+
contents: write
|
|
59
|
+
attestations: write
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/download-artifact@v4
|
|
62
|
+
with:
|
|
63
|
+
pattern: wheels-*
|
|
64
|
+
merge-multiple: true
|
|
65
|
+
path: dist
|
|
66
|
+
- uses: actions/attest-build-provenance@v1
|
|
67
|
+
with:
|
|
68
|
+
subject-path: "dist/*"
|
|
69
|
+
- uses: PyO3/maturin-action@v1
|
|
70
|
+
with:
|
|
71
|
+
command: upload
|
|
72
|
+
args: --non-interactive --skip-existing dist/*
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.nox/
|
|
42
|
+
.coverage
|
|
43
|
+
.coverage.*
|
|
44
|
+
.cache
|
|
45
|
+
nosetests.xml
|
|
46
|
+
coverage.xml
|
|
47
|
+
*.cover
|
|
48
|
+
*.py,cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
|
|
52
|
+
# Translations
|
|
53
|
+
*.mo
|
|
54
|
+
*.pot
|
|
55
|
+
|
|
56
|
+
# Django stuff:
|
|
57
|
+
*.log
|
|
58
|
+
local_settings.py
|
|
59
|
+
db.sqlite3
|
|
60
|
+
db.sqlite3-journal
|
|
61
|
+
|
|
62
|
+
# Flask stuff:
|
|
63
|
+
instance/
|
|
64
|
+
.webassets-cache
|
|
65
|
+
|
|
66
|
+
# Scrapy stuff:
|
|
67
|
+
.scrapy
|
|
68
|
+
|
|
69
|
+
# Sphinx documentation
|
|
70
|
+
docs/_build/
|
|
71
|
+
|
|
72
|
+
# PyBuilder
|
|
73
|
+
target/
|
|
74
|
+
|
|
75
|
+
# Jupyter Notebook
|
|
76
|
+
.ipynb_checkpoints
|
|
77
|
+
|
|
78
|
+
# IPython
|
|
79
|
+
profile_default/
|
|
80
|
+
ipython_config.py
|
|
81
|
+
|
|
82
|
+
# pyenv
|
|
83
|
+
.python-version
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
Pipfile.lock
|
|
87
|
+
|
|
88
|
+
# PEP 582
|
|
89
|
+
__pypackages__/
|
|
90
|
+
|
|
91
|
+
# Celery stuff
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
celerybeat.pid
|
|
94
|
+
|
|
95
|
+
# SageMath parsed files
|
|
96
|
+
*.sage.py
|
|
97
|
+
|
|
98
|
+
# Environments
|
|
99
|
+
.env
|
|
100
|
+
.venv
|
|
101
|
+
env/
|
|
102
|
+
venv/
|
|
103
|
+
ENV/
|
|
104
|
+
env.bak/
|
|
105
|
+
venv.bak/
|
|
106
|
+
|
|
107
|
+
# Spyder project settings
|
|
108
|
+
.spyderproject
|
|
109
|
+
.spyproject
|
|
110
|
+
|
|
111
|
+
# Rope project settings
|
|
112
|
+
.ropeproject
|
|
113
|
+
|
|
114
|
+
# mkdocs documentation
|
|
115
|
+
/site
|
|
116
|
+
|
|
117
|
+
# mypy
|
|
118
|
+
.mypy_cache/
|
|
119
|
+
.dmypy.json
|
|
120
|
+
dmypy.json
|
|
121
|
+
|
|
122
|
+
# Pyre type checker
|
|
123
|
+
.pyre/
|
|
124
|
+
|
|
125
|
+
# Rust build artifacts
|
|
126
|
+
/target/
|
|
127
|
+
Cargo.lock
|
|
128
|
+
|
|
129
|
+
# IDE
|
|
130
|
+
.zed/
|
|
131
|
+
.idea/
|
|
132
|
+
.vscode/
|
|
133
|
+
*.swp
|
|
134
|
+
*.swo
|
|
135
|
+
*~
|
|
136
|
+
.DS_Store
|
|
137
|
+
|
|
138
|
+
# Maturin
|
|
139
|
+
dist/
|
|
140
|
+
build/
|