Skip to main content

Xarray + Polars: an xarray Dataset paired with per-dimension Polars frames that stay aligned under selection.

Project description

xolars

Xarray + polars: an xarray Dataset paired with one Polars frame per dimension, kept aligned to the Dataset's coordinate order — including under isel/sel selection and zarr + parquet round-trips.

Install

uv add xolars      # or: pip install xolars

Usage

import numpy as np
import polars as pl
import xarray as xr
from xolars import Xolars

ds = xr.Dataset(
    {"expr": (["gene_id", "sample_id"], np.arange(12.0).reshape(3, 4))},
    coords={"gene_id": ["G1", "G2", "G3"], "sample_id": ["S1", "S2", "S3", "S4"]},
)
genes = pl.DataFrame({"gene_id": ["G1", "G2", "G3"], "chrom": ["c1", "c2", "c3"]})

xol = Xolars(ds=ds, df={"gene_id": genes})

# Selection filters the Dataset AND every per-dimension frame, together:
sub = xol.sel(gene_id=["G3", "G1"])
assert list(sub.df["gene_id"]["gene_id"]) == list(sub.ds["gene_id"].values)

# Persist to zarr (Dataset) + parquet (per-dim frames), then reopen lazily:
xol.write("mydata.xolars", mode="w")
reloaded = Xolars.open("mydata.xolars")        # frames are pl.LazyFrame
eager = reloaded.collect()                      # -> pl.DataFrame

Xolars is a frozen, generic container: Xolars[pl.LazyFrame] after open, Xolars[pl.DataFrame] after collect. Construction validates that each frame's dim column exactly matches the Dataset coordinate (same set, same multiplicity) and reorders rows to the Dataset's order.

Development

uv sync                          # create .venv with runtime + dev deps
uv run pytest -q                 # tests
uv run prek run --all-files      # ruff + pyrefly + hygiene hooks
uv run prek install              # enable git hooks locally

Releasing

Releases run via the manual Release GitHub Actions workflow (workflow_dispatch), which uses commitizen to bump the version from conventional commits, tag, create a GitHub release, and publish to PyPI via OIDC trusted publishing. Before the workflow can succeed, the following one-time setup is required on GitHub (out of scope for the initial extraction):

  1. Push this repository to https://github.com/d-laub/xolars.
  2. Add a GH_ACTIONS repository secret (a PAT able to push to main) so the bump commit + tag can be pushed past branch protection.
  3. Configure a pypi environment and enable PyPI trusted publishing for the xolars project pointing at the publish job.

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

xolars-0.2.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

xolars-0.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file xolars-0.2.1.tar.gz.

File metadata

  • Download URL: xolars-0.2.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for xolars-0.2.1.tar.gz
Algorithm Hash digest
SHA256 82e912a2b02feb263b0b0f0f36bc092d4c7ad967fff507d5d587bd52dbf1d868
MD5 fc857b121367353460d9b28aa6717165
BLAKE2b-256 22605d2b3e36c771e4a57185f3b49025a8e6e9e9b12eaea4e0630395fcbfd5ff

See more details on using hashes here.

File details

Details for the file xolars-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: xolars-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for xolars-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d3048b311f1a14006f84c31c426293094073ff4d797ae01479eb0a11009c12d
MD5 dc4b5e70f55d8937c06759f1746eea3c
BLAKE2b-256 bb95b77efb330885686ca69c73bf3900492384adfcd2bddb68b70985b60807f7

See more details on using hashes here.

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