wayne
trade a formula to model matrix
"Greet each day with a smile, so it doesn't know what you're planning on doing to it." - Wayne
Formula to Model Matrix in One Function Call
wyane is a Python package that converts statistical formulas into model matrices using Polars DataFrames. It does one thing: takes a formula and a DataFrame, returns a model matrix.
Installation
Requirements: Python 3.13+ (due to fiasto-py dependency)
uv pip install wayne-trade
# or
pip install wayne-trade
Usage
import wayne
import polars as pl
# Load your data
df = pl.read_csv("data/mtcars.csv")
# Define your formula
formula = 'mpg ~ cyl + wt*hp + poly(disp, 4) - 1'
# Get the model matrix
model_matrix = wayne.trade_formula_for_matrix(df, formula)
print(model_matrix)
Wayne Speak Fiasto
Wayne provides a clean interface to fiasto-py's parsing functionality without requiring users to directly import fiasto-py and deal with its maturin/pyo3 complexity:
import wayne
# Parse a formula to get detailed structure
result = wayne.speak_fiasto("mpg ~ cyl + wt*hp + poly(disp, 4) - 1")
print(result['columns'].keys()) # All variables and their metadata
print(result['metadata']['has_intercept']) # Formula metadata
print(result['all_generated_columns']) # All generated column names
Features
- Single Function:
trade_formula_for_matrix(df, formula) - Polars Integration: Works with Polars DataFrames
- R-Style Formulas: Supports R/Wilkinson notation
- Fast Parsing: Rust + fiasto for formula parsing
- Orthogonal Polynomials: NumPy-based polynomial generation
- Interactions: Handles interaction terms (e.g.,
x*z) - Intercept Control: Add/remove intercept with
+1/-1
Formula Syntax
Wayne supports R-style statistical formulas:
- Basic terms:
y ~ x + z - Interactions:
y ~ x*z(expands tox + z + x:z) - Polynomial terms:
y ~ poly(x, 3)(generates 3 orthogonal polynomial columns) - Intercept control:
y ~ x - 1(removes intercept) - Complex formulas:
y ~ x + z + poly(w, 3) + x:z - 1
Examples
See the examples/ directory for complete examples:
# Main example
uv run python examples/final_example.py
# Single function demo
uv run python examples/single_function_example.py
What You Get
The model matrix contains:
- Main effects: Original variables from your formula
- Interaction terms: Generated interaction columns (e.g.,
wt_hpforwt*hp) - Polynomial terms: Orthogonal polynomial columns (e.g.,
disp_poly_1,disp_poly_2, etc.)
Development & Releases
For developers and maintainers:
- Release Process: See RELEASE.md for how to release new versions to PyPI
- Automatic Releases: Pushing changes to
CHANGELOG.mdtriggers automatic PyPI releases - Testing: Run
uv run -m pytestto run the test suite - Polynomial Validation: Run
uv run compare_polynomials.pyto verify R compatibility - Intercept: Optional intercept column
Perfect for Statistical Modeling
Wayne creates model matrices that are ready for:
- Linear regression
- Generalized linear models
- Mixed effects models
- Any statistical modeling that needs a design matrix
License
MIT
Metadata
Release files for wayne-trade 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wayne_trade-0.1.8.tar.gz | 10.0 kB | Without provenance | Details for wayne_trade-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wayne_trade-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for wayne_trade-0.1.8-py3-none-any.whl |
Total release size: 16.9 kB
Release files / wayne_trade-0.1.8.tar.gz
| Download URL | wayne_trade-0.1.8.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24372a05ed5827d885110779457aab35025e504db2faef53890a4cc97926dad1
|
|
BLAKE2b-256 checksum How to use checksums |
12b0d18866bf8c62be1fa50069f6aca0bcad12e45ff508a2c9f54e36bede2510
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.19
|
Release files / wayne_trade-0.1.8-py3-none-any.whl
| Download URL | wayne_trade-0.1.8-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb36083017b27e9b2362f90df44a503c607f7bc6c233dd1d0ed121d44b5e6bed
|
|
BLAKE2b-256 checksum How to use checksums |
3cf649f223bfad7b4b870e366eea424db70ebb51ca69f89e902daf88d8951cad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.19
|
Security for wayne-trade 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.