Expression namespace (.ta)¶
Importing polars_ta registers a .ta accessor on every Polars expression, so
indicators read like native Polars methods:
import polars as pl
import polars_ta # registers .ta on import
df.with_columns(
pl.col("close").ta.rsi(14).alias("rsi"),
pl.col("high").ta.average_true_range("low", "close").alias("atr"),
)
The expression you call .ta on is bound to the indicator's first input
(close for most, high for the high-anchored ones); remaining columns are
passed as arguments. It's the same code as the module-level functions — a
byte-for-byte-identical dispatch layer — so .over(...), streaming and fillna
all work through it. polars_ta.TA_INDICATORS lists every exposed name.
Cross-sectional and regime-composite helpers, which take a generic value column or two pre-built signals rather than a single price series, stay free-function-only.
See the how-to guide for the full calling convention.
polars_ta.namespace
¶
Native Polars expression namespace: pl.col("close").ta.<indicator>(...).
Registering a .ta namespace on pl.Expr lets every indicator be called
as a method on the expression that supplies its primary price input, instead
of passing a column name into a free function::
df.with_columns(
pl.col("close").ta.rsi(14).alias("rsi"),
pl.col("high").ta.average_true_range("low", "close").alias("atr"),
)
The calling expression is bound to the indicator's first positional
argument — which is close for most indicators, high for the
high-anchored ones (stoch, average_true_range, aroon_up, ...), and
open for the candlestick patterns (pl.col("open").ta.cdl_doji()). Every
remaining input column is passed as an ordinary argument, exactly as the free
function takes it, so nothing about the underlying math or signatures changes:
the namespace is a thin dispatch layer over the same functions in
:mod:polars_ta.momentum, :mod:polars_ta.trend, and friends. Because each
method returns a plain pl.Expr, .over("symbol") and the streaming engine
work through the namespace unchanged.
The free-function API is unaffected — this is purely additive. A handful of
functions are intentionally not exposed here (cross_sectional_zscore /
cross_sectional_rank take a generic value column rather than a price series,
and regime_conditional_signal arbitrates between two pre-built signal
expressions); call those as free functions.
TAExpr
¶
TAExpr(expr: Expr)
The .ta accessor on a Polars expression.
See the module docstring for the calling convention. Every method here is generated from the corresponding free function at import time, so the namespace can never drift out of sync with the indicator implementations.
Source code in polars_ta/namespace.py
168 169 | |