Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Function

pl.arange

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.

How it works

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.

Syntax

polars.arange(start: int | IntoExprColumn = 0, end: int | IntoExprColumn | None = None, step: int = 1, *, dtype: PolarsIntegerType | DataTypeExpr = Int64, eager: bool = False) → Expr | Series

Parameters

NameTypeDescription
startint | IntoExprColumnInclusive lower bound; defaults to 0.
endint | IntoExprColumn | NoneExclusive upper bound; defaults to None.
stepintIncrement between values; defaults to 1.
dtypePolarsIntegerType | DataTypeExprOutput data type; defaults to Int64.
eagerboolWhether to evaluate immediately; defaults to False.

Returns

Expr or SeriesColumn of integer data type dtype.

Key points

  • Use pl.arange to construct integer sequences.
  • The function is an alternate name for int_range.
  • The start value belongs to the range when the sequence reaches it.
  • step determines the distance between consecutive generated integers.
  • Use dtype to choose the output integer type.
  • Setting eager=True evaluates the range immediately as a Series.

Common mistakes

  • The default returns an expression rather than a Series, so use eager=True when immediate evaluation is required.
  • The end value is not included in the generated range.

Example: Create an integer Series

import polars as pl

values = pl.arange(0, 6, 2, eager=True)
print(values)

Creates an eager Series containing 0, 2, and 4.

When to use it

Eager sequence creation

Create a contiguous or stepped integer Series for immediate Python-side use.

Lazy expression construction

Build an integer-range expression as part of a Polars query.

Typed integer ranges

Generate values with an explicitly selected Polars integer dtype.

Interview questions

QWhat does pl.arange return by default?

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.

QHow are range boundaries and increments interpreted?

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.

QHow does pl.arange relate to other Polars range functions?

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_range
  • int_ranges

Source: polars.arange — Polars documentation. Checked 2026-10-15.