Skip to content

ucon.integrations.polars

Polars integration via NumberColumn. Install with pip install ucon[polars].

Polars integration for ucon.

This module provides NumberColumn for working with unit-aware Polars Series.

Requires: pip install ucon[polars]

Example

import polars as pl from ucon import units from ucon.polars import NumberColumn

heights = NumberColumn(pl.Series([1.7, 1.8, 1.9]), unit=units.meter) heights.to(units.foot)

NumberColumn

A Polars Series with an associated unit.

Combines a Polars Series of magnitudes with a unit, enabling vectorized arithmetic and conversion.

Parameters

series : pl.Series The numeric values. unit : Unit or UnitProduct, optional The unit for all values. Defaults to dimensionless. uncertainty : float or pl.Series, optional Uncertainty value(s). If scalar, applies uniformly to all elements. If Series, must have the same length.

Examples

import polars as pl from ucon import units from ucon.polars import NumberColumn

Create from Series:

heights = NumberColumn(pl.Series([1.7, 1.8, 1.9]), unit=units.meter) len(heights) 3

Vectorized conversion:

heights_ft = heights.to(units.foot)

series property

The underlying Polars Series.

unit property

The unit shared by all values.

uncertainty property

The uncertainty (scalar or per-element Series).

shape property

Shape of the series.

dtype property

Data type of the series.

dimension property

The physical dimension of the quantities.

__len__()

Return the number of elements.

__getitem__(key)

Index or slice the series.

__iter__()

Iterate as Number instances.

__repr__()

String representation.

__mul__(other)

Multiply by scalar, Number, or NumberColumn.

__rmul__(other)

Right multiplication.

__truediv__(other)

Divide by scalar, Number, or NumberColumn.

__add__(other)

Add NumberColumn or Number (same unit required).

__radd__(other)

Right addition.

__sub__(other)

Subtract NumberColumn or Number (same unit required).

__neg__()

Negation.

__abs__()

Absolute value.

__eq__(other)

Element-wise equality comparison. Returns boolean Series.

__ne__(other)

Element-wise inequality comparison. Returns boolean Series.

__lt__(other)

Element-wise less-than comparison. Returns boolean Series.

__le__(other)

Element-wise less-than-or-equal comparison. Returns boolean Series.

__gt__(other)

Element-wise greater-than comparison. Returns boolean Series.

__ge__(other)

Element-wise greater-than-or-equal comparison. Returns boolean Series.

to(target, graph=None)

Convert all values to a different unit.

Parameters

target : Unit or UnitProduct The target unit to convert to. graph : ConversionGraph, optional The conversion graph to use. Defaults to the global default graph.

Returns

NumberColumn A new NumberColumn with converted values.

sum()

Sum all values.

mean()

Compute the mean.

std(ddof=1)

Compute the standard deviation.

min()

Return the minimum value.

max()

Return the maximum value.

to_list()

Convert to a list of Number instances.