Expand grid functionality using Polars
Project description
Polarsgrid
Tidyverse-style expand_grid() in a fast and efficient way using Polars.
Installation
Install the package as follows:
pip install polarsgrid
or add it to your project using uv as follows:
uv add polarsgrid
Usage
This package contains one main function: expand_grid().
from polarsgrid import expand_grid
expand_grid(a=range(2), b=["x", "y"])
shape: (4, 2)
┌─────┬─────┐
│ a ┆ b │
│ --- ┆ --- │
│ i64 ┆ str │
╞═════╪═════╡
│ 0 ┆ x │
│ 1 ┆ x │
│ 0 ┆ y │
│ 1 ┆ y │
└─────┴─────┘
Note that the first argument iteratest fastest, and the last argument iterates slowest in the cartesian product.
Should the grid become too big to hold in memory, you can choose to return a lazy table which can be stored on a disk efficiently:
from polarsgrid import expand_grid_lazy
lgrid = expand_grid_lazy(
sample_size=range(1000),
condition=["a", "b", "c"],
iteration=range(500),
)
lgrid.sink_parquet("grid.parquet")
Additionally, for certain operations it might be nice to return the string columns as a categorical data type, and to add a row id:
expand_grid(
fruit=["apple", "banana", "pear"],
color=["red", "green", "blue"],
check=[True, False],
_categorical=True,
_row_id=True,
)
shape: (18, 4)
┌────────┬────────┬───────┬───────┐
│ row_id ┆ fruit ┆ color ┆ check │
│ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ cat ┆ cat ┆ bool │
╞════════╪════════╪═══════╪═══════╡
│ 0 ┆ apple ┆ red ┆ true │
│ 1 ┆ banana ┆ red ┆ true │
│ 2 ┆ pear ┆ red ┆ true │
│ 3 ┆ apple ┆ green ┆ true │
│ 4 ┆ banana ┆ green ┆ true │
│ … ┆ … ┆ … ┆ … │
│ 13 ┆ banana ┆ green ┆ false │
│ 14 ┆ pear ┆ green ┆ false │
│ 15 ┆ apple ┆ blue ┆ false │
│ 16 ┆ banana ┆ blue ┆ false │
│ 17 ┆ pear ┆ blue ┆ false │
└────────┴────────┴───────┴───────┘
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 polarsgrid-0.4.0.tar.gz.
File metadata
- Download URL: polarsgrid-0.4.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc1a67c2be336d75bf0595fa788cb40a7f506975b4025c381340b23255e5b3ce
|
|
| MD5 |
5504e45a34f8d16bf6b39d750c909501
|
|
| BLAKE2b-256 |
1f86efd3bd3a51f8c998b1bd9bbc6831bc649d6e2335ff2218d375ff7a17df0e
|
Provenance
The following attestation bundles were made for polarsgrid-0.4.0.tar.gz:
Publisher:
publish.yml on vankesteren/polarsgrid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polarsgrid-0.4.0.tar.gz -
Subject digest:
cc1a67c2be336d75bf0595fa788cb40a7f506975b4025c381340b23255e5b3ce - Sigstore transparency entry: 1065788507
- Sigstore integration time:
-
Permalink:
vankesteren/polarsgrid@505bdea2cf2434866da7605337c4bf41b8900867 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/vankesteren
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@505bdea2cf2434866da7605337c4bf41b8900867 -
Trigger Event:
release
-
Statement type:
File details
Details for the file polarsgrid-0.4.0-py3-none-any.whl.
File metadata
- Download URL: polarsgrid-0.4.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1e6328515194020e7a8132f2392585393c10942117fcebde55719bfdb5fa4a8
|
|
| MD5 |
e28a9156dbfe5c394768602c0b36f71a
|
|
| BLAKE2b-256 |
aee0a440ad519705fa5f7615b46312153175ac0966e5cdc36fa7e0d9f38b393f
|
Provenance
The following attestation bundles were made for polarsgrid-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on vankesteren/polarsgrid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polarsgrid-0.4.0-py3-none-any.whl -
Subject digest:
c1e6328515194020e7a8132f2392585393c10942117fcebde55719bfdb5fa4a8 - Sigstore transparency entry: 1065788509
- Sigstore integration time:
-
Permalink:
vankesteren/polarsgrid@505bdea2cf2434866da7605337c4bf41b8900867 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/vankesteren
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@505bdea2cf2434866da7605337c4bf41b8900867 -
Trigger Event:
release
-
Statement type: