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.0.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.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xolars-0.2.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","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.0.tar.gz
Algorithm Hash digest
SHA256 50d991167fe1d7296ec42e63993f1bee5e13a45ae2fb85fd14d3b28d9b61385a
MD5 0aa6ebc46bf9612de4b1cb2e3b187f2c
BLAKE2b-256 834760d6fcf4487baedd96dcf4180e5b56ecfb634061727c95972fac48f98afd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xolars-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f2ca8447061966f25a56bc8d60f4053dc7a8e0475b5d64ecad0b9c0a610425e
MD5 d90e91c03cdfea606f4f085d77b4a907
BLAKE2b-256 97f1d1f542ee2b3230de79ef61e3b11d4a950eb338b232b6fec72bdc4bf5989e

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