Skip to main content

Polars

SigilYX is built for Polars. Importing sigilyx registers official Polars namespace plugins that make YXDB files feel like a native Polars format.

Reading

DataFrame

import polars as pl
import sigilyx

# Read the entire file into a DataFrame
df = pl.read_yxdb("data.yxdb")

This is the fastest read path. Data transfers from Rust to Python via the Arrow C Data Interface with zero copies.

LazyFrame

# Returns a LazyFrame - only the header is read upfront
lf = pl.scan_yxdb("data.yxdb")

# Data is streamed from Rust on .collect()
result = lf.filter(pl.col("amount") > 100).select("id", "name").collect()

Projection pushdown and row-limit pushdown are supported. See Lazy Scan for details.

Equivalent Direct API

import sigilyx as yx

df = yx.read_yxdb("data.yxdb") # Same as pl.read_yxdb()
lf = yx.scan("data.yxdb") # Same as pl.scan_yxdb()

Writing

From a DataFrame

# Using the namespace plugin
df.yxdb.write("output.yxdb")

# Or using the direct API
import sigilyx as yx
yx.write_yxdb("output.yxdb", df)

From a LazyFrame

# Collect and write in one step
lf.yxdb.sink("output.yxdb")

This collects the LazyFrame and writes the result to a YXDB file.

Type Mapping

Polars types are mapped to YXDB field types as follows:

Polars TypeYXDB TypeNotes
BooleanBoolean
Int16Int16Byte maps to Int16 on read
Int32Int32
Int64Int64
Float32Float
Float64Double
DecimalFixedDecimalPrecision and scale preserved
StringString / WStringFixed-width strings
StringV_String / V_WStringVariable-length strings
DateDateDays since epoch
DatetimeDateTimeMicrosecond precision
TimeTimeNanosecond precision
BinaryBlobRaw bytes

Common Patterns

Read, transform, write

import polars as pl
import sigilyx

df = pl.read_yxdb("input.yxdb")

result = (
df
.filter(pl.col("status") == "active")
.with_columns(
pl.col("revenue").cast(pl.Float64).alias("revenue_float"),
)
.group_by("region")
.agg(pl.col("revenue_float").sum().alias("total_revenue"))
.sort("total_revenue", descending=True)
)

result.yxdb.write("output.yxdb")

Convert YXDB to Parquet

import polars as pl
import sigilyx

pl.read_yxdb("data.yxdb").write_parquet("data.parquet")

Convert Parquet to YXDB

import polars as pl
import sigilyx

pl.read_parquet("data.parquet").yxdb.write("data.yxdb")

Read only specific columns (lazy)

import polars as pl
import sigilyx

result = (
pl.scan_yxdb("large_file.yxdb")
.select("id", "name", "email")
.head(1000)
.collect()
)

Only the three selected columns are materialized, and reading stops after 1,000 rows.