Eager sequence creation
Create a contiguous or stepped integer Series for immediate Python-side use.
Polars · Function
pl.arange generates an integer range with an inclusive start and exclusive end. It returns an expression by default or an eagerly evaluated Series when eager=True.
pl.arange produces integer values from an inclusive start up to, but not including, an exclusive end, advancing by step. By default it returns a lazy expression; eager=True evaluates it immediately as a Series, and dtype controls the integer type.
polars.arange(start: int | IntoExprColumn = 0, end: int | IntoExprColumn | None = None, step: int = 1, *, dtype: PolarsIntegerType | DataTypeExpr = Int64, eager: bool = False) → Expr | Series| Name | Type | Description |
|---|---|---|
start | int | IntoExprColumn | Inclusive lower bound; defaults to 0. |
end | int | IntoExprColumn | None | Exclusive upper bound; defaults to None. |
step | int | Increment between values; defaults to 1. |
dtype | PolarsIntegerType | DataTypeExpr | Output data type; defaults to Int64. |
eager | bool | Whether to evaluate immediately; defaults to False. |
Expr or SeriesColumn of integer data type dtype.
import polars as pl
values = pl.arange(0, 6, 2, eager=True)
print(values)
Creates an eager Series containing 0, 2, and 4.
Create a contiguous or stepped integer Series for immediate Python-side use.
Build an integer-range expression as part of a Polars query.
Generate values with an explicitly selected Polars integer dtype.
pl.arange generates an integer range with an inclusive start and exclusive end. Its default result is an Expr, while eager=True evaluates immediately and returns a Series.
Follow-up: How would you generate values with a different integer type? Pass the desired Polars integer dtype through dtype.
The start parameter sets the inclusive lower bound, end sets the exclusive upper bound, and step controls the increment. If end is omitted, the function can still accept the documented range inputs through its expression-oriented API.
Follow-up: What boundary behavior should tests verify? They should confirm that start is present when reachable and end is absent.
pl.arange is an alias for int_range, so both names represent integer-range generation. int_ranges is the related function for generating a range independently for each input row.
Follow-up: Which related function is intended for row-wise ranges? Use int_ranges rather than a single shared range.
int_rangeint_ranges