Helpers for the Arrow-backed Python stack: polars, pyarrow, duckdb.
Project description
arrow-dx
Helpers for the Arrow-backed Python stack: polars, pyarrow, duckdb. Small, theme-bound — each helper smooths a rough edge in day-to-day dataframe work, nothing more.
Install
pip install arrow-dx
# optional extras
pip install "arrow-dx[pandas]"
pip install "arrow-dx[pyarrow]"
pip install "arrow-dx[duckdb]"
pip install "arrow-dx[all]"
Requires Python 3.13+. Only polars is a hard runtime dependency.
Helpers
unify_schema(root, *, output_dir=None, type_overrides=None, on_conflict="supertype", column_order=None)
Rewrite every *.parquet under root to share one schema. Use case: a hive-partitioned dataset where files written at different times have drifted — a column added later, a type widened, a column missing in older files. After unification every reader (polars, pyarrow, duckdb, pandas) handles the dataset with its bare-minimum call.
from arrow_dx import unify_schema
# rewrite files in place
unify_schema("data/")
# or copy into a new tree, preserving the partition layout
unify_schema("data/", output_dir="data-unified/")
on_conflict∈{"supertype" (default), "string", "error"}— how to resolve a column whose type differs across files.type_overrides={"col": pl.String}— pin specific columns; wins over conflict resolution.column_order=[...]— pin a column-order prefix; remaining columns follow in first-seen order.- Hive
key=valuepartition columns are auto-detected and excluded from the file schema.
sample_print(df, n=10, seed=None)
Print n contiguous rows from a random offset in a sorted polars, pandas, or pyarrow dataframe. Defeats each engine's default row-clipping so the full window is visible. Caller is responsible for sorting first — the slice is contiguous, so it's only meaningful in some intentional order. pyarrow Dataset (lazy) is out of scope; call .to_table() first.
from arrow_dx import sample_print
sample_print(polars_df, n=10, seed=42)
sample_print(pandas_df, n=10, seed=42)
sample_print(pyarrow_table, n=10, seed=42)
summarize(t, *, group_by=None, con=None)
Per-column summary statistics for a parquet dataset (or any duckdb-readable thing). Returns one row per column: column_name, column_type, min, max, n_unique, avg, std, q25, q50, q75, count, null_perc. Numeric stats are formatted to 4 significant figures and decimal-aligned for compact display. min/max are nulled for VARCHAR columns (lexical bounds rarely meaningful); DATE columns keep YYYY-MM-DD format in aggregates. Quantiles are exact (duckdb spills to disk if needed) and the underlying SUMMARIZE runs streaming, so 100M-row datasets don't materialize.
from arrow_dx import summarize
summarize("data/**/*.parquet")
summarize("data/**/*.parquet", group_by="region") # column-major: each column across regions
summarize("orders", con=my_con) # use a registered table
t is a catalog table/view name, parquet file path, or parquet glob. group_by runs a separate SUMMARIZE per distinct value — fast for low-cardinality columns (regions, years), slow for high-cardinality ones (user_id, sku). To summarize an in-memory polars DataFrame, register it on a connection first: con.register("df", my_df); summarize("df", con=con).
Requires the duckdb extra: pip install "arrow-dx[duckdb]".
DuckDB
sample_print is also shipped as a duckdb SQL macro. To install it for the duckdb CLI:
uvx arrow-dx duckdb-macros >> ~/.duckdbrc
Then in any CLI session:
SELECT * FROM sample_print('orders', 10); -- catalog table
SELECT * FROM sample_print('s3://bucket/data.parquet', 10); -- single file
SELECT * FROM sample_print('data/**/*.parquet', 10, seed := 42); -- glob, deterministic
The argument is a string — a catalog table/view name, a parquet file path, or a parquet glob ('dir/**/*.parquet'). Caller still owns sort order. With seed := <int> the offset is deterministic; without it, a fresh random offset each call. The duckdb CLI's row-clip is .maxrows N in your ~/.duckdbrc, separate from the macro.
For Python users with an open connection:
import duckdb
from arrow_dx.duckdb import install_macros
con = duckdb.connect()
install_macros(con)
con.sql("SELECT * FROM sample_print('mytable', 10, seed := 42)")
Reports
arrow_dx.report.markdown(t) renders a one-page markdown report — header (path, rows, size, partition count), schema (arrow / polars / duckdb types side-by-side + null %), summary (per-column min/max/avg/std/quartiles via duckdb's SUMMARIZE, plus an inline sparkline for numeric columns), hive-partition breakdown, and a contiguous-window sample.
from arrow_dx import markdown
# print to stdout
print(markdown("data/**/*.parquet"))
# write to a file alongside the data
markdown("data/**/*.parquet", output="data/REPORT.md", sample_n=20, sample_seed=1)
Options:
style="markdown"(default) renders pipe-and-dash tables that markdown viewers turn into styled tables;style="box"switches to Unicode box-drawing tables (┌─┬─┐) wrapped in code fences for monospace contexts (terminals, plain-text files). Sparklines and histograms always use Unicode block characters.per_partition=Trueadds a Per-partition summary section faceted by the leftmost hive column (low-cardinality only — runs oneSUMMARIZEper group).sparklines=True(default) adds asparklinecolumn to the Summary table for numeric columns, showing the per-column distribution in 10 buckets via Unicode block chars (▁▂▃▄▅▆▇█).histograms=True(opt-in) adds a Histograms section with full bar-chart per numeric column — bin edges, bar, count.
Drop-in for code review, dataset onboarding, or living docs alongside the data. Deterministic sample seed by default so re-running on unchanged data produces a stable diff.
Requires the duckdb extra: pip install "arrow-dx[duckdb]".
Scope
In: ergonomics for the Arrow-backed dataframe stack — polars, pyarrow, duckdb (+ pandas as an extra). Out: anything that doesn't fit that theme. The discipline keeps this from rotting into a junk drawer.
Project details
Release history Release notifications | RSS feed
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 arrow_dx-0.1.2.tar.gz.
File metadata
- Download URL: arrow_dx-0.1.2.tar.gz
- Upload date:
- Size: 42.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcaa8303a65375595e148c2f98a103c2ec0920ff9354578295ee41bb10d97aff
|
|
| MD5 |
ac962cd3b4e053cb42b99f18e97c5731
|
|
| BLAKE2b-256 |
846a64ed80514ac096a71374d71edf848c1a11828b9ffc3162d1d413ec9967e8
|
Provenance
The following attestation bundles were made for arrow_dx-0.1.2.tar.gz:
Publisher:
publish.yml on twedl/arrow-dx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arrow_dx-0.1.2.tar.gz -
Subject digest:
bcaa8303a65375595e148c2f98a103c2ec0920ff9354578295ee41bb10d97aff - Sigstore transparency entry: 1510658530
- Sigstore integration time:
-
Permalink:
twedl/arrow-dx@926950d287edb6bcded83f8a42afc424609dacc1 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/twedl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@926950d287edb6bcded83f8a42afc424609dacc1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file arrow_dx-0.1.2-py3-none-any.whl.
File metadata
- Download URL: arrow_dx-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da006790a69958d1dd9540197c2bc486b8f14d9e9fef3ccaf3c7439d5ae150b6
|
|
| MD5 |
8fa57dc426255b244da621590de43e73
|
|
| BLAKE2b-256 |
1096f0ad3659d96768dfcc091dd295bf8e6538b145fb79732df6247f80af903f
|
Provenance
The following attestation bundles were made for arrow_dx-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on twedl/arrow-dx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arrow_dx-0.1.2-py3-none-any.whl -
Subject digest:
da006790a69958d1dd9540197c2bc486b8f14d9e9fef3ccaf3c7439d5ae150b6 - Sigstore transparency entry: 1510658635
- Sigstore integration time:
-
Permalink:
twedl/arrow-dx@926950d287edb6bcded83f8a42afc424609dacc1 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/twedl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@926950d287edb6bcded83f8a42afc424609dacc1 -
Trigger Event:
push
-
Statement type: