Skip to main content

Expand grid functionality using Polars

Project description

Polarsgrid

Continuous integration PyPI - Python Version

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

polarsgrid-0.4.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polarsgrid-0.4.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

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

Hashes for polarsgrid-0.4.0.tar.gz
Algorithm Hash digest
SHA256 cc1a67c2be336d75bf0595fa788cb40a7f506975b4025c381340b23255e5b3ce
MD5 5504e45a34f8d16bf6b39d750c909501
BLAKE2b-256 1f86efd3bd3a51f8c998b1bd9bbc6831bc649d6e2335ff2218d375ff7a17df0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for polarsgrid-0.4.0.tar.gz:

Publisher: publish.yml on vankesteren/polarsgrid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for polarsgrid-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1e6328515194020e7a8132f2392585393c10942117fcebde55719bfdb5fa4a8
MD5 e28a9156dbfe5c394768602c0b36f71a
BLAKE2b-256 aee0a440ad519705fa5f7615b46312153175ac0966e5cdc36fa7e0d9f38b393f

See more details on using hashes here.

Provenance

The following attestation bundles were made for polarsgrid-0.4.0-py3-none-any.whl:

Publisher: publish.yml on vankesteren/polarsgrid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page