Skip to main content

polars-list-zip-struct

polars-list-zip-struct is a native expression plugin for the accepted Polars list.zip proposal from pola-rs/polars#22719.

It adds:

  • pl.col("a").list.zip(pl.col("b"), pad=False)
  • pl.zip_list("a", "b", "c", pad=False)

Both return a list[struct] expression. By default, lists are truncated to the shortest input, like Python's zip. With pad=True, shorter lists are padded with nulls to match the longest input. Struct fields default to the input column/expression names, matching the upstream Polars pull request.

If a future Polars release ships native list.zip or pl.zip_list, this package leaves the native implementation untouched.

Installation

pip install polars-list-zip-struct

The package supports Polars releases from roughly the last three months onward and does not cap future Polars versions. For this release that means polars>=1.39.3.

Usage

Import the package once to register the Polars helpers:

import polars as pl
import polars_list_zip_struct  # noqa: F401

df = pl.DataFrame(
    {
        "a": [[1, 2], [3], None, [None]],
        "b": [[10, 20], [30, 35], [40], [35]],
    }
)

out = df.with_columns(
    pl.col("a").list.zip(pl.col("b")).alias("zipped")
)
shape: (4, 3)
┌───────────┬───────────┬──────────────────┐
│ a         ┆ b         ┆ zipped           │
│ ---       ┆ ---       ┆ ---              │
│ list[i64] ┆ list[i64] ┆ list[struct[2]]  │
╞═══════════╪═══════════╪══════════════════╡
│ [1, 2]    ┆ [10, 20]  ┆ [{1,10}, {2,20}] │
│ [3]       ┆ [30, 35]  ┆ [{3,30}]         │
│ null      ┆ [40]      ┆ null             │
│ [null]    ┆ [35]      ┆ [{null,35}]      │
└───────────┴───────────┴──────────────────┘

Zip more than two list expressions with pl.zip_list:

df.with_columns(
    pl.zip_list("a", "b", "c", fields=["a", "b", "c"]).alias("all_zipped")
)

Use pad=True for zip_longest behavior:

df.with_columns(
    pl.col("a").list.zip(pl.col("b"), pad=True).alias("zipped")
)

Notes

The core implementation is a Rust Polars expression plugin built with pyo3-polars. It follows the original upstream implementation idea: build a LargeListArray of StructArray values with Arrow builders, offsets, and row validity, rather than running a Python row loop.

Development

python -m pip install -e ".[dev]"
maturin develop
python -m pytest

Build and upload:

python -m pip install ".[publish]"
maturin build --release
python -m twine upload target/wheels/*

Metadata

Release files for polars-list-zip-struct 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars-list-zip-struct 0.1.1
File Size Uploaded Provenance
polars_list_zip_struct-0.1.1.tar.gz 23.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for polars-list-zip-struct 0.1.1
File Interpreter ABI Platform
polars_list_zip_struct-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details

Total release size: 5.3 MB

Release files / polars_list_zip_struct-0.1.1.tar.gz

Download URL polars_list_zip_struct-0.1.1.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
53c63fb2e017314e3ddb368a6c0a84ab4a90b30f889bc320fe09b5c9179e8f51
BLAKE2b-256 checksum
How to use checksums
8ae461418ae008f9eedfe0850e2a2bd07013d2d10df4a82f5f42e23bf195fafe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / polars_list_zip_struct-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL polars_list_zip_struct-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Size 5.3 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
25c440e5f080ba50ad8f97424c1c088914f36d3a74b16001592698378bb34155
BLAKE2b-256 checksum
How to use checksums
b37aa8814252218545e3134e26086e499a2ed1e92150121dce9673bd286baa6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for polars-list-zip-struct 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page