CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-polars-lts-cpu

Blazingly fast DataFrame library for legacy CPUs without AVX2 support

Pending
Overview
Eval results
Files

functions.mddocs/

Functions

Rich collection of functions for data manipulation including aggregation, lazy operations, range generation, mathematical operations, and utility functions. These functions provide the building blocks for complex data transformations and computations.

Capabilities

Column Selection and Manipulation

Core functions for selecting and manipulating columns in DataFrames and LazyFrames.

def col(name: str | list[str]) -> Expr:
    """
    Select column(s) by name.
    
    Parameters:
    - name: Column name(s) to select
    
    Returns:
    - Expr: Column selection expression
    """

def lit(value: Any) -> Expr:
    """
    Create literal value expression.
    
    Parameters:
    - value: Literal value (int, float, str, bool, etc.)
    
    Returns:
    - Expr: Literal expression
    """

def when(predicate: IntoExpr) -> ExprWhenThen:
    """
    Start conditional expression chain.
    
    Parameters:
    - predicate: Boolean condition
    
    Returns:
    - ExprWhenThen: Conditional expression builder
    """

def exclude(*columns: str | list[str]) -> Expr:
    """
    Exclude specified columns from selection.
    
    Parameters:
    - columns: Column names to exclude
    
    Returns:
    - Expr: Column exclusion expression
    """

def select(*exprs: IntoExpr) -> Expr:
    """
    Select expressions for DataFrame operations.
    
    Parameters:
    - exprs: Expressions to select
    
    Returns:
    - Expr: Selection expression
    """

Aggregation Functions

Functions for computing aggregations across rows or columns.

def sum(*args: IntoExpr) -> Expr:
    """
    Sum values.
    
    Parameters:
    - args: Expressions to sum
    
    Returns:
    - Expr: Sum expression
    """

def mean(*args: IntoExpr) -> Expr:
    """
    Compute mean of values.
    
    Parameters:
    - args: Expressions to average
    
    Returns:
    - Expr: Mean expression
    """

def max(*args: IntoExpr) -> Expr:
    """
    Find maximum values.
    
    Parameters:
    - args: Expressions to find max of
    
    Returns:
    - Expr: Maximum expression
    """

def min(*args: IntoExpr) -> Expr:
    """
    Find minimum values.
    
    Parameters:
    - args: Expressions to find min of
    
    Returns:
    - Expr: Minimum expression
    """

def count(*args: IntoExpr) -> Expr:
    """
    Count values.
    
    Parameters:
    - args: Expressions to count
    
    Returns:
    - Expr: Count expression
    """

def median(*args: IntoExpr) -> Expr:
    """
    Compute median of values.
    
    Parameters:
    - args: Expressions to find median of
    
    Returns:
    - Expr: Median expression
    """

def std(*args: IntoExpr, ddof: int = 1) -> Expr:
    """
    Compute standard deviation.
    
    Parameters:
    - args: Expressions to compute std of
    - ddof: Delta degrees of freedom
    
    Returns:
    - Expr: Standard deviation expression
    """

def var(*args: IntoExpr, ddof: int = 1) -> Expr:
    """
    Compute variance.
    
    Parameters:
    - args: Expressions to compute variance of
    - ddof: Delta degrees of freedom
    
    Returns:
    - Expr: Variance expression
    """

def quantile(*args: IntoExpr, quantile: float, interpolation: str = "nearest") -> Expr:
    """
    Compute quantile.
    
    Parameters:
    - args: Expressions to compute quantile of
    - quantile: Quantile value (0.0 to 1.0)
    - interpolation: Interpolation method
    
    Returns:
    - Expr: Quantile expression
    """

Horizontal Aggregations

Functions for computing aggregations across columns horizontally.

def sum_horizontal(*exprs: IntoExpr) -> Expr:
    """
    Sum values horizontally across columns.
    
    Parameters:
    - exprs: Column expressions to sum
    
    Returns:
    - Expr: Horizontal sum expression
    """

def mean_horizontal(*exprs: IntoExpr) -> Expr:
    """
    Compute mean horizontally across columns.
    
    Parameters:
    - exprs: Column expressions to average
    
    Returns:
    - Expr: Horizontal mean expression
    """

def max_horizontal(*exprs: IntoExpr) -> Expr:
    """
    Find maximum horizontally across columns.
    
    Parameters:
    - exprs: Column expressions to find max of
    
    Returns:
    - Expr: Horizontal maximum expression
    """

def min_horizontal(*exprs: IntoExpr) -> Expr:
    """
    Find minimum horizontally across columns.
    
    Parameters:
    - exprs: Column expressions to find min of
    
    Returns:
    - Expr: Horizontal minimum expression
    """

def all_horizontal(*exprs: IntoExpr) -> Expr:
    """
    Logical AND horizontally across columns.
    
    Parameters:
    - exprs: Boolean column expressions
    
    Returns:
    - Expr: Horizontal all expression
    """

def any_horizontal(*exprs: IntoExpr) -> Expr:
    """
    Logical OR horizontally across columns.
    
    Parameters:
    - exprs: Boolean column expressions
    
    Returns:
    - Expr: Horizontal any expression
    """

Boolean Logic Functions

Functions for boolean operations across columns and rows.

def all(*args: IntoExpr) -> Expr:
    """
    Check if all values are true.
    
    Parameters:
    - args: Boolean expressions
    
    Returns:
    - Expr: All expression
    """

def any(*args: IntoExpr) -> Expr:
    """
    Check if any values are true.
    
    Parameters:
    - args: Boolean expressions
    
    Returns:
    - Expr: Any expression
    """

Cumulative Functions

Functions for cumulative operations and reductions.

def cum_sum(*args: IntoExpr, reverse: bool = False) -> Expr:
    """
    Compute cumulative sum.
    
    Parameters:
    - args: Expressions to compute cumulative sum of
    - reverse: Compute in reverse order
    
    Returns:
    - Expr: Cumulative sum expression
    """

def cum_sum_horizontal(*exprs: IntoExpr) -> Expr:
    """
    Compute cumulative sum horizontally across columns.
    
    Parameters:
    - exprs: Column expressions
    
    Returns:
    - Expr: Horizontal cumulative sum expression
    """

def cum_count(*args: IntoExpr, reverse: bool = False) -> Expr:
    """
    Compute cumulative count.
    
    Parameters:
    - args: Expressions to count
    - reverse: Compute in reverse order
    
    Returns:
    - Expr: Cumulative count expression
    """

def cum_fold(
    acc: IntoExpr,
    function: Callable[[Expr, Expr], Expr],
    *exprs: IntoExpr,
    include_init: bool = False
) -> Expr:
    """
    Cumulatively fold expressions with a function.
    
    Parameters:
    - acc: Initial accumulator value
    - function: Folding function
    - exprs: Expressions to fold
    - include_init: Include initial value in result
    
    Returns:
    - Expr: Cumulative fold expression
    """

def cum_reduce(expression: Expr) -> Expr:
    """
    Cumulatively reduce expression.
    
    Parameters:
    - expression: Expression to reduce
    
    Returns:
    - Expr: Cumulative reduce expression
    """

Range Functions

Functions for generating ranges and sequences of values.

def arange(
    start: int | IntoExpr,
    end: int | IntoExpr,
    step: int = 1,
    *,
    eager: bool = False
) -> Expr | Series:
    """
    Create range of integers.
    
    Parameters:
    - start: Start value (inclusive)
    - end: End value (exclusive)
    - step: Step size
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Integer range
    """

def int_range(
    start: int | IntoExpr,
    end: int | IntoExpr | None = None,
    step: int = 1,
    *,
    eager: bool = False
) -> Expr | Series:
    """
    Create range of integers.
    
    Parameters:
    - start: Start value or end if end is None
    - end: End value (exclusive)
    - step: Step size
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Integer range
    """

def int_ranges(
    start: int | IntoExpr,
    end: int | IntoExpr,
    step: int = 1,
    *,
    eager: bool = False
) -> Expr | Series:
    """
    Create multiple integer ranges.
    
    Parameters:
    - start: Start values
    - end: End values
    - step: Step size
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: List of integer ranges
    """

def date_range(
    start: date | datetime | IntoExpr,
    end: date | datetime | IntoExpr,
    interval: str | timedelta = "1d",
    *,
    closed: str = "both",
    eager: bool = False
) -> Expr | Series:
    """
    Create range of dates.
    
    Parameters:
    - start: Start date
    - end: End date
    - interval: Date interval (e.g., '1d', '1w', '1mo')
    - closed: Include endpoints ('both', 'left', 'right', 'none')
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Date range
    """

def date_ranges(
    start: date | datetime | IntoExpr,
    end: date | datetime | IntoExpr,
    interval: str | timedelta = "1d",
    *,
    closed: str = "both",
    eager: bool = False
) -> Expr | Series:
    """
    Create multiple date ranges.
    
    Returns:
    - Expr | Series: List of date ranges
    """

def datetime_range(
    start: datetime | IntoExpr,
    end: datetime | IntoExpr,
    interval: str | timedelta = "1d",
    *,
    closed: str = "both",
    time_unit: str | None = None,
    time_zone: str | None = None,
    eager: bool = False
) -> Expr | Series:
    """
    Create range of datetimes.
    
    Parameters:
    - start: Start datetime
    - end: End datetime
    - interval: Datetime interval
    - closed: Include endpoints
    - time_unit: Time precision ('ns', 'us', 'ms')
    - time_zone: Timezone
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Datetime range
    """

def datetime_ranges(
    start: datetime | IntoExpr,
    end: datetime | IntoExpr,
    interval: str | timedelta = "1d",
    *,
    closed: str = "both",
    time_unit: str | None = None,
    time_zone: str | None = None,
    eager: bool = False
) -> Expr | Series:
    """
    Create multiple datetime ranges.
    
    Returns:
    - Expr | Series: List of datetime ranges
    """

def time_range(
    start: time | IntoExpr | None = None,
    end: time | IntoExpr | None = None,
    interval: str | timedelta = "1h",
    *,
    closed: str = "both",
    eager: bool = False
) -> Expr | Series:
    """
    Create range of times.
    
    Parameters:
    - start: Start time
    - end: End time
    - interval: Time interval
    - closed: Include endpoints
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Time range
    """

def time_ranges(
    start: time | IntoExpr,
    end: time | IntoExpr,
    interval: str | timedelta = "1h",
    *,
    closed: str = "both",
    eager: bool = False
) -> Expr | Series:
    """
    Create multiple time ranges.
    
    Returns:
    - Expr | Series: List of time ranges
    """

Linear Space Functions

Functions for generating linearly spaced values.

def linear_space(
    start: int | float | IntoExpr,
    end: int | float | IntoExpr,
    num: int,
    *,
    endpoint: bool = True,
    dtype: type = Float64,
    eager: bool = False
) -> Expr | Series:
    """
    Create linearly spaced values.
    
    Parameters:
    - start: Start value
    - end: End value
    - num: Number of values
    - endpoint: Include endpoint
    - dtype: Data type of result
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Linearly spaced values
    """

def linear_spaces(
    start: int | float | IntoExpr,
    end: int | float | IntoExpr,
    num: int,
    *,
    endpoint: bool = True,
    dtype: type = Float64,
    eager: bool = False
) -> Expr | Series:
    """
    Create multiple linear spaces.
    
    Returns:
    - Expr | Series: List of linearly spaced values
    """

Data Type Constructor Functions

Functions for creating typed literal values and structures.

def date(year: int, month: int, day: int) -> date:
    """
    Create date value.
    
    Parameters:
    - year: Year
    - month: Month (1-12)
    - day: Day of month
    
    Returns:
    - date: Date object
    """

def datetime(
    year: int,
    month: int,
    day: int,
    hour: int = 0,
    minute: int = 0,
    second: int = 0,
    microsecond: int = 0,
    *,
    time_unit: str = "us",
    time_zone: str | None = None
) -> datetime:
    """
    Create datetime value.
    
    Parameters:
    - year: Year
    - month: Month
    - day: Day
    - hour: Hour
    - minute: Minute
    - second: Second
    - microsecond: Microsecond
    - time_unit: Time precision
    - time_zone: Timezone
    
    Returns:
    - datetime: Datetime object
    """

def time(
    hour: int = 0,
    minute: int = 0,
    second: int = 0,
    microsecond: int = 0
) -> time:
    """
    Create time value.
    
    Parameters:
    - hour: Hour (0-23)
    - minute: Minute (0-59)
    - second: Second (0-59)
    - microsecond: Microsecond
    
    Returns:
    - time: Time object
    """

def duration(
    *,
    weeks: int | IntoExpr | None = None,
    days: int | IntoExpr | None = None,
    hours: int | IntoExpr | None = None,
    minutes: int | IntoExpr | None = None,
    seconds: int | IntoExpr | None = None,
    milliseconds: int | IntoExpr | None = None,
    microseconds: int | IntoExpr | None = None,
    nanoseconds: int | IntoExpr | None = None,
    time_unit: str = "us"
) -> Expr:
    """
    Create duration expression.
    
    Parameters:
    - weeks: Number of weeks
    - days: Number of days
    - hours: Number of hours
    - minutes: Number of minutes
    - seconds: Number of seconds
    - milliseconds: Number of milliseconds
    - microseconds: Number of microseconds
    - nanoseconds: Number of nanoseconds
    - time_unit: Time precision
    
    Returns:
    - Expr: Duration expression
    """

def struct(*exprs: IntoExpr, schema: list[str] | None = None, **named_exprs: IntoExpr) -> Expr:
    """
    Create struct expression from fields.
    
    Parameters:
    - exprs: Field expressions
    - schema: Field names
    - named_exprs: Named field expressions
    
    Returns:
    - Expr: Struct expression
    """

def struct_with_fields(fields: Sequence[Expr]) -> Expr:
    """
    Create struct expression with explicit fields.
    
    Parameters:
    - fields: Field expressions
    
    Returns:
    - Expr: Struct expression
    """

String and Concatenation Functions

Functions for string operations and concatenation.

def concat_str(*exprs: IntoExpr, separator: str = "", ignore_nulls: bool = False) -> Expr:
    """
    Concatenate string expressions.
    
    Parameters:
    - exprs: String expressions to concatenate
    - separator: Separator between strings
    - ignore_nulls: Skip null values
    
    Returns:
    - Expr: Concatenated string expression
    """

def concat_list(*exprs: IntoExpr) -> Expr:
    """
    Concatenate expressions into list.
    
    Parameters:
    - exprs: Expressions to concatenate
    
    Returns:
    - Expr: List expression
    """

def concat_arr(*exprs: IntoExpr) -> Expr:
    """
    Concatenate expressions into array.
    
    Parameters:
    - exprs: Expressions to concatenate
    
    Returns:
    - Expr: Array expression
    """

def format(format_str: str, *args: IntoExpr) -> Expr:
    """
    Format string with expressions.
    
    Parameters:
    - format_str: Format string with {} placeholders
    - args: Expressions to format
    
    Returns:
    - Expr: Formatted string expression
    """

def escape_regex(value: str) -> str:
    """
    Escape regex special characters in string.
    
    Parameters:
    - value: String to escape
    
    Returns:
    - str: Escaped string
    """

Mathematical Functions

Functions for mathematical operations.

def arctan2(y: str | Expr, x: str | Expr) -> Expr:
    """
    Compute element-wise arc tangent of y/x in radians.
    
    Parameters:
    - y: Y coordinates
    - x: X coordinates
    
    Returns:
    - Expr: Arc tangent expression
    """

def arctan2d(y: str | Expr, x: str | Expr) -> Expr:
    """
    Compute element-wise arc tangent of y/x in degrees.
    
    Parameters:
    - y: Y coordinates
    - x: X coordinates
    
    Returns:
    - Expr: Arc tangent expression in degrees
    """

Statistical Functions

Functions for correlation and covariance.

def corr(a: IntoExpr, b: IntoExpr, *, method: str = "pearson", ddof: int = 1) -> Expr:
    """
    Compute correlation between two expressions.
    
    Parameters:
    - a: First expression
    - b: Second expression
    - method: Correlation method ('pearson', 'spearman')
    - ddof: Delta degrees of freedom
    
    Returns:
    - Expr: Correlation expression
    """

def cov(a: IntoExpr, b: IntoExpr, *, ddof: int = 1) -> Expr:
    """
    Compute covariance between two expressions.
    
    Parameters:
    - a: First expression
    - b: Second expression
    - ddof: Delta degrees of freedom
    
    Returns:
    - Expr: Covariance expression
    """

def rolling_corr(
    a: IntoExpr,
    b: IntoExpr,
    window_size: int,
    *,
    ddof: int = 1
) -> Expr:
    """
    Compute rolling correlation.
    
    Parameters:
    - a: First expression
    - b: Second expression
    - window_size: Rolling window size
    - ddof: Delta degrees of freedom
    
    Returns:
    - Expr: Rolling correlation expression
    """

def rolling_cov(
    a: IntoExpr,
    b: IntoExpr,
    window_size: int,
    *,
    ddof: int = 1
) -> Expr:
    """
    Compute rolling covariance.
    
    Parameters:
    - a: First expression
    - b: Second expression
    - window_size: Rolling window size
    - ddof: Delta degrees of freedom
    
    Returns:
    - Expr: Rolling covariance expression
    """

Utility Functions

Miscellaneous utility functions for data manipulation.

def coalesce(*exprs: IntoExpr) -> Expr:
    """
    Return first non-null value from expressions.
    
    Parameters:
    - exprs: Expressions to check
    
    Returns:
    - Expr: Coalesced expression
    """

def from_epoch(column: IntoExpr, time_unit: str = "s") -> Expr:
    """
    Convert epoch timestamp to datetime.
    
    Parameters:
    - column: Epoch timestamp expression
    - time_unit: Time unit of input ('s', 'ms', 'us', 'ns')
    
    Returns:
    - Expr: Datetime expression
    """

def approx_n_unique(column: IntoExpr) -> Expr:
    """
    Approximate number of unique values.
    
    Parameters:
    - column: Column expression
    
    Returns:
    - Expr: Approximate unique count expression
    """

def n_unique(column: IntoExpr) -> Expr:
    """
    Count unique values.
    
    Parameters:
    - column: Column expression
    
    Returns:
    - Expr: Unique count expression
    """

def dtype_of(column: IntoExpr) -> Expr:
    """
    Get data type of expression.
    
    Parameters:
    - column: Expression to check
    
    Returns:
    - Expr: Data type expression
    """

def self_dtype() -> Expr:
    """
    Get data type of current column context.
    
    Returns:
    - Expr: Self data type expression
    """

Array Creation Functions

Functions for creating arrays with specific patterns.

def ones(shape: int | tuple[int, ...], *, dtype: type = Float64, eager: bool = False) -> Expr | Series:
    """
    Create array filled with ones.
    
    Parameters:
    - shape: Array shape
    - dtype: Data type
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Array of ones
    """

def zeros(shape: int | tuple[int, ...], *, dtype: type = Float64, eager: bool = False) -> Expr | Series:
    """
    Create array filled with zeros.
    
    Parameters:
    - shape: Array shape
    - dtype: Data type
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Array of zeros
    """

def repeat(
    value: IntoExpr,
    n: int | IntoExpr,
    *,
    eager: bool = False
) -> Expr | Series:
    """
    Repeat value n times.
    
    Parameters:
    - value: Value to repeat
    - n: Number of repetitions
    - eager: Return Series instead of Expr
    
    Returns:
    - Expr | Series: Repeated values
    """

Collection Functions

Functions for working with multiple DataFrames and LazyFrames.

def collect_all(
    lazy_frames: list[LazyFrame],
    *,
    type_coercion: bool = True,
    predicate_pushdown: bool = True,
    projection_pushdown: bool = True,
    simplify_expression: bool = True,
    slice_pushdown: bool = True,
    comm_subplan_elim: bool = True,
    comm_subexpr_elim: bool = True,
    streaming: bool = False
) -> list[DataFrame]:
    """
    Collect multiple LazyFrames with shared optimization.
    
    Parameters:
    - lazy_frames: List of LazyFrames to collect
    - type_coercion: Enable type coercion optimization
    - predicate_pushdown: Enable predicate pushdown
    - projection_pushdown: Enable projection pushdown
    - simplify_expression: Enable expression simplification
    - slice_pushdown: Enable slice pushdown
    - comm_subplan_elim: Enable common subplan elimination
    - comm_subexpr_elim: Enable common subexpression elimination
    - streaming: Enable streaming execution
    
    Returns:
    - list[DataFrame]: Collected DataFrames
    """

def collect_all_async(
    lazy_frames: list[LazyFrame],
    *,
    gevent: bool = False,
    **kwargs
) -> Awaitable[list[DataFrame]]:
    """
    Collect multiple LazyFrames asynchronously.
    
    Parameters:
    - lazy_frames: List of LazyFrames to collect
    - gevent: Use gevent for async execution
    - **kwargs: Same optimization parameters as collect_all
    
    Returns:
    - Awaitable[list[DataFrame]]: Async collected DataFrames
    """

def concat(
    items: Iterable[DataFrame | LazyFrame | Series],
    *,
    rechunk: bool = False,
    how: str = "vertical",
    parallel: bool = True
) -> DataFrame | LazyFrame | Series:
    """
    Concatenate DataFrames, LazyFrames, or Series.
    
    Parameters:
    - items: Items to concatenate
    - rechunk: Rechunk result for better memory layout
    - how: Concatenation method ('vertical', 'horizontal', 'diagonal')
    - parallel: Use parallel concatenation
    
    Returns:
    - DataFrame | LazyFrame | Series: Concatenated result
    """

Other Utility Functions

Additional utility functions for various operations.

def first(*args: IntoExpr) -> Expr:
    """Get first value."""

def last(*args: IntoExpr) -> Expr:
    """Get last value."""

def nth(column: IntoExpr, n: int | IntoExpr) -> Expr:
    """Get nth value."""

def head(*args: IntoExpr, n: int = 10) -> Expr:
    """Get first n values."""

def tail(*args: IntoExpr, n: int = 10) -> Expr:
    """Get last n values."""

def groups() -> Expr:
    """Get group indices."""

def implode(column: IntoExpr) -> Expr:
    """Collect values into list."""

def len() -> Expr:
    """Get length."""

def element() -> Expr:
    """Get single element from length-1 Series."""

def arg_sort_by(*by: IntoExpr, descending: bool = False) -> Expr:
    """Get indices that would sort by expressions."""

def arg_where(condition: IntoExpr) -> Expr:
    """Get indices where condition is true."""

def business_day_count(
    start: IntoExpr,
    end: IntoExpr,
    *,
    week_mask: list[bool] = [True, True, True, True, True, False, False],
    holidays: list[date] | None = None
) -> Expr:
    """Count business days between dates."""

def set_random_seed(seed: int) -> None:
    """Set random seed for reproducible operations."""

def field(name: str) -> Expr:
    """Select struct field."""

def fold(
    acc: IntoExpr,
    function: Callable[[Expr, Expr], Expr],
    *exprs: IntoExpr
) -> Expr:
    """Fold expressions with function."""

def reduce(function: Callable[[Expr, Expr], Expr], *exprs: IntoExpr) -> Expr:
    """Reduce expressions with function."""

def map_batches(
    function: Callable[[DataFrame], DataFrame],
    *exprs: IntoExpr,
    returns_scalar: bool = False,
    agg_list: bool = False
) -> Expr:
    """Apply function to DataFrame batches."""

def map_groups(
    function: Callable[[DataFrame], DataFrame],
    *exprs: IntoExpr,
    returns_scalar: bool = False
) -> Expr:
    """Apply function to grouped DataFrames."""

def align_frames(
    *frames: DataFrame | LazyFrame,
    on: str | Expr | list[str | Expr],
    select: str | Expr | list[str | Expr] | None = None,
    reverse: bool | list[bool] = False
) -> list[DataFrame | LazyFrame]:
    """Align frames on common values."""

def row_index() -> Expr:
    """Add row index column."""

def explain_all(*lazy_frames: LazyFrame, **kwargs) -> None:
    """Print query plans for multiple LazyFrames."""

def sql_expr(sql: str) -> Expr:
    """Create expression from SQL fragment."""

Usage Examples

Basic Function Usage

import polars as pl

df = pl.DataFrame({
    "a": [1, 2, 3, 4],
    "b": [10, 20, 30, 40],
    "c": [100, 200, 300, 400]
})

# Column selection and manipulation
result = df.select([
    pl.col("a"),
    pl.lit(42).alias("literal"),
    pl.when(pl.col("a") > 2).then(pl.col("b")).otherwise(0).alias("conditional")
])

# Aggregations
agg_result = df.select([
    pl.sum("a").alias("sum_a"),
    pl.mean("b").alias("mean_b"),
    pl.max("c").alias("max_c"),
    pl.count().alias("count")
])

Horizontal Operations

# Horizontal aggregations
result = df.with_columns([
    pl.sum_horizontal("a", "b", "c").alias("row_sum"),
    pl.max_horizontal("a", "b", "c").alias("row_max"),
    pl.mean_horizontal("a", "b", "c").alias("row_mean")
])

Range Functions

# Create ranges
ranges_df = pl.DataFrame({
    "int_range": pl.arange(0, 10, eager=True),
    "date_range": pl.date_range(
        pl.date(2023, 1, 1),
        pl.date(2023, 1, 10),
        "1d",
        eager=True
    )
})

# Linear space
linear_vals = pl.linear_space(0, 100, 11, eager=True)

String Operations

text_df = pl.DataFrame({
    "first": ["hello", "world"],
    "second": ["polars", "rocks"]
})

result = text_df.select([
    pl.concat_str("first", "second", separator=" ").alias("combined"),
    pl.format("{} is {}", pl.col("first"), pl.col("second")).alias("formatted")
])

Mathematical Functions

coords_df = pl.DataFrame({
    "x": [1.0, 2.0, 3.0],
    "y": [1.0, 2.0, 3.0]
})

result = coords_df.with_columns([
    pl.arctan2("y", "x").alias("angle_rad"),
    pl.arctan2d("y", "x").alias("angle_deg")
])

Statistical Functions

stats_df = pl.DataFrame({
    "x": [1, 2, 3, 4, 5],
    "y": [2, 4, 6, 8, 10]
})

result = stats_df.select([
    pl.corr("x", "y").alias("correlation"),
    pl.cov("x", "y").alias("covariance")
])

Collection Operations

# Multiple LazyFrames
lazy1 = pl.scan_csv("file1.csv")
lazy2 = pl.scan_csv("file2.csv")
lazy3 = pl.scan_csv("file3.csv")

# Collect all with shared optimization
results = pl.collect_all([lazy1, lazy2, lazy3])

# Concatenate DataFrames
combined = pl.concat([results[0], results[1], results[2]], how="vertical")

Advanced Function Usage

# Cumulative operations
cumulative_df = df.select([
    pl.col("a"),
    pl.cum_sum("a").alias("cumsum_a"),
    pl.cum_count("a").alias("cumcount_a")
])

# Complex folding
folded = df.select([
    pl.fold(
        acc=pl.lit(0),
        function=lambda acc, x: acc + x,
        exprs=["a", "b", "c"]
    ).alias("total")
])

# Utility functions
utility_result = df.select([
    pl.coalesce("a", pl.lit(0)).alias("coalesced"),
    pl.n_unique("a").alias("unique_count"),
    pl.dtype_of("a").alias("data_type")
])

Install with Tessl CLI

npx tessl i tessl/pypi-polars-lts-cpu

docs

configuration.md

core-classes.md

data-types.md

expressions.md

functions.md

index.md

io-operations.md

sql-functionality.md

tile.json