Documentation
¶
Overview ¶
Package expr defines the golars expression AST.
Expressions are immutable values. Users build them through package-level constructors and fluent methods:
expr.Col("price").Mul(expr.Col("qty")).Alias("revenue")
expr.Col("x").GtLit(int64(10)).And(expr.Col("y").IsNotNull())
Expressions describe a computation on a DataFrame. They are executed either eagerly through Eval or indirectly through the lazy planner. The same AST drives both paths.
Index ¶
- func Columns(e Expr) []string
- func ContainsAgg(e Expr) bool
- func Equal(a, b Expr) bool
- func OutputName(e Expr) string
- func Walk(e Expr, fn func(Expr) bool)
- type AggNode
- type AggOp
- type AliasNode
- type BinaryNode
- type BinaryOp
- type CastNode
- type ColNode
- type Expr
- func All(preds ...Expr) Expr
- func Any(preds ...Expr) Expr
- func Children(e Expr) []Expr
- func Coalesce(exprs ...Expr) Expr
- func Col(name string) Expr
- func ConcatStr(sep string, exprs ...Expr) Expr
- func IntRange(start, end, step int64) Expr
- func Lit(v any) Expr
- func LitBool(v bool) Expr
- func LitFloat64(v float64) Expr
- func LitInt64(v int64) Expr
- func LitNull(dt dtype.DType) Expr
- func LitOf[T Scalar](v T) Expr
- func LitString(v string) Expr
- func Not(e Expr) Expr
- func Ones(n int) Expr
- func WithChildren(e Expr, children []Expr) Expr
- func Zeros(n int) Expr
- func (e Expr) Abs() Expr
- func (e Expr) Add(other Expr) Expr
- func (e Expr) AddLit(v any) Expr
- func (e Expr) Alias(name string) Expr
- func (e Expr) All() Expr
- func (e Expr) And(other Expr) Expr
- func (e Expr) Any() Expr
- func (e Expr) ApproxNUnique() Expr
- func (e Expr) Arccos() Expr
- func (e Expr) Arccosh() Expr
- func (e Expr) Arcsin() Expr
- func (e Expr) Arcsinh() Expr
- func (e Expr) Arctan() Expr
- func (e Expr) Arctan2(other Expr) Expr
- func (e Expr) Arctanh() Expr
- func (e Expr) BackwardFill(limit int) Expr
- func (e Expr) Between(lo, hi any) Expr
- func (e Expr) Cast(to dtype.DType) Expr
- func (e Expr) Cbrt() Expr
- func (e Expr) Ceil() Expr
- func (e Expr) Clip(lo, hi float64) Expr
- func (e Expr) Cos() Expr
- func (e Expr) Cosh() Expr
- func (e Expr) Cot() Expr
- func (e Expr) Count() Expr
- func (e Expr) CumCount() Expr
- func (e Expr) CumMax() Expr
- func (e Expr) CumMin() Expr
- func (e Expr) CumProd() Expr
- func (e Expr) CumSum() Expr
- func (e Expr) Degrees() Expr
- func (e Expr) Diff(periods int) Expr
- func (e Expr) Div(other Expr) Expr
- func (e Expr) DivLit(v any) Expr
- func (e Expr) EWMMean(alpha float64) Expr
- func (e Expr) EWMStd(alpha float64) Expr
- func (e Expr) EWMVar(alpha float64) Expr
- func (e Expr) Entropy(base float64) Expr
- func (e Expr) Eq(other Expr) Expr
- func (e Expr) EqLit(v any) Expr
- func (e Expr) Exp() Expr
- func (e Expr) Expm1() Expr
- func (e Expr) FillNan(v float64) Expr
- func (e Expr) FillNull(v any) Expr
- func (e Expr) FillNullExpr(other Expr) Expr
- func (e Expr) First() Expr
- func (e Expr) Floor() Expr
- func (e Expr) ForwardFill(limit int) Expr
- func (e Expr) Ge(other Expr) Expr
- func (e Expr) GeLit(v any) Expr
- func (e Expr) Gt(other Expr) Expr
- func (e Expr) GtLit(v any) Expr
- func (e Expr) Hash() uint64
- func (e Expr) HashValues() Expr
- func (e Expr) Head(n int) Expr
- func (e Expr) IsDuplicated() Expr
- func (e Expr) IsFirstDistinct() Expr
- func (e Expr) IsIn(values ...any) Expr
- func (e Expr) IsLastDistinct() Expr
- func (e Expr) IsNotNull() Expr
- func (e Expr) IsNull() Expr
- func (e Expr) IsUnique() Expr
- func (e Expr) Kurtosis() Expr
- func (e Expr) Last() Expr
- func (e Expr) Le(other Expr) Expr
- func (e Expr) LeLit(v any) Expr
- func (e Expr) List() ListOps
- func (e Expr) Log() Expr
- func (e Expr) Log1p() Expr
- func (e Expr) Log2() Expr
- func (e Expr) Log10() Expr
- func (e Expr) Lt(other Expr) Expr
- func (e Expr) LtLit(v any) Expr
- func (e Expr) Max() Expr
- func (e Expr) Mean() Expr
- func (e Expr) Median() Expr
- func (e Expr) Min() Expr
- func (e Expr) Mul(other Expr) Expr
- func (e Expr) MulLit(v any) Expr
- func (e Expr) NUnique() Expr
- func (e Expr) Ne(other Expr) Expr
- func (e Expr) NeLit(v any) Expr
- func (e Expr) Neg() Expr
- func (e Expr) Node() Node
- func (e Expr) Not() Expr
- func (e Expr) NullCount() Expr
- func (e Expr) Or(other Expr) Expr
- func (e Expr) Over(keys ...string) Expr
- func (e Expr) PctChange(periods int) Expr
- func (e Expr) PeakMax() Expr
- func (e Expr) PeakMin() Expr
- func (e Expr) Pow(exponent float64) Expr
- func (e Expr) Product() Expr
- func (e Expr) Quantile(q float64) Expr
- func (e Expr) Radians() Expr
- func (e Expr) Rank(method string) Expr
- func (e Expr) Reverse() Expr
- func (e Expr) RollingMax(windowSize, minPeriods int) Expr
- func (e Expr) RollingMean(windowSize, minPeriods int) Expr
- func (e Expr) RollingMin(windowSize, minPeriods int) Expr
- func (e Expr) RollingStd(windowSize, minPeriods int) Expr
- func (e Expr) RollingSum(windowSize, minPeriods int) Expr
- func (e Expr) RollingVar(windowSize, minPeriods int) Expr
- func (e Expr) Round(decimals int) Expr
- func (e Expr) Shift(periods int) Expr
- func (e Expr) Sign() Expr
- func (e Expr) Sin() Expr
- func (e Expr) Sinh() Expr
- func (e Expr) Skew() Expr
- func (e Expr) Slice(offset, length int) Expr
- func (e Expr) Sort(descending bool) Expr
- func (e Expr) Sqrt() Expr
- func (e Expr) Std() Expr
- func (e Expr) Str() StrOps
- func (e Expr) String() string
- func (e Expr) Struct() StructOps
- func (e Expr) Sub(other Expr) Expr
- func (e Expr) SubLit(v any) Expr
- func (e Expr) Sum() Expr
- func (e Expr) Tail(n int) Expr
- func (e Expr) Tan() Expr
- func (e Expr) Tanh() Expr
- func (e Expr) Unique() Expr
- func (e Expr) Var() Expr
- type FunctionNode
- type IsNullNode
- type ListOps
- func (o ListOps) Contains(needle any) Expr
- func (o ListOps) First() Expr
- func (o ListOps) Get(idx int) Expr
- func (o ListOps) Join(sep string) Expr
- func (o ListOps) Last() Expr
- func (o ListOps) Len() Expr
- func (o ListOps) Max() Expr
- func (o ListOps) Mean() Expr
- func (o ListOps) Min() Expr
- func (o ListOps) Sum() Expr
- type LitNode
- type Node
- type OverNode
- type Scalar
- type StrOps
- func (o StrOps) Contains(needle string) Expr
- func (o StrOps) ContainsRegex(pattern string) Expr
- func (o StrOps) CountMatches(needle string) Expr
- func (o StrOps) EndsWith(suffix string) Expr
- func (o StrOps) Find(needle string) Expr
- func (o StrOps) Head(n int) Expr
- func (o StrOps) LenBytes() Expr
- func (o StrOps) LenChars() Expr
- func (o StrOps) Like(pattern string) Expr
- func (o StrOps) NotLike(pattern string) Expr
- func (o StrOps) Replace(old, new string) Expr
- func (o StrOps) ReplaceAll(old, new string) Expr
- func (o StrOps) Slice(start, length int) Expr
- func (o StrOps) SplitExact(sep string) Expr
- func (o StrOps) StartsWith(prefix string) Expr
- func (o StrOps) StripPrefix(prefix string) Expr
- func (o StrOps) StripSuffix(suffix string) Expr
- func (o StrOps) Tail(n int) Expr
- func (o StrOps) ToLower() Expr
- func (o StrOps) ToUpper() Expr
- func (o StrOps) Trim() Expr
- type StructOps
- type TCol
- func (c TCol[T]) Abs() TCol[T]
- func (c TCol[T]) Add(v T) TCol[T]
- func (c TCol[T]) AddCol(o TCol[T]) TCol[T]
- func (c TCol[T]) Alias(name string) TCol[T]
- func (c TCol[T]) ApproxNUnique() TCol[int64]
- func (c TCol[T]) As(name string) TCol[T]
- func (c TCol[T]) BackwardFill(limit int) TCol[T]
- func (c TCol[T]) Between(lo, hi T) Expr
- func (c TCol[T]) CastBool() TCol[bool]
- func (c TCol[T]) CastFloat64() TCol[float64]
- func (c TCol[T]) CastInt64() TCol[int64]
- func (c TCol[T]) CastString() TCol[string]
- func (c TCol[T]) CastTo(to dtype.DType) Expr
- func (c TCol[T]) Count() TCol[int64]
- func (c TCol[T]) CumCount() TCol[int64]
- func (c TCol[T]) CumMax() TCol[T]
- func (c TCol[T]) CumMin() TCol[T]
- func (c TCol[T]) CumProd() TCol[T]
- func (c TCol[T]) CumSum() TCol[T]
- func (c TCol[T]) Diff(periods int) TCol[T]
- func (c TCol[T]) Div(v T) TCol[T]
- func (c TCol[T]) DivCol(o TCol[T]) TCol[T]
- func (c TCol[T]) Eq(v T) Expr
- func (c TCol[T]) EqCol(o TCol[T]) Expr
- func (c TCol[T]) FillNull(v T) TCol[T]
- func (c TCol[T]) First() TCol[T]
- func (c TCol[T]) ForwardFill(limit int) TCol[T]
- func (c TCol[T]) Ge(v T) Expr
- func (c TCol[T]) GeCol(o TCol[T]) Expr
- func (c TCol[T]) Gt(v T) Expr
- func (c TCol[T]) GtCol(o TCol[T]) Expr
- func (c TCol[T]) Head(n int) TCol[T]
- func (c TCol[T]) IsIn(values ...T) Expr
- func (c TCol[T]) IsNotNull() Expr
- func (c TCol[T]) IsNull() Expr
- func (c TCol[T]) Kurtosis() TCol[float64]
- func (c TCol[T]) Last() TCol[T]
- func (c TCol[T]) Le(v T) Expr
- func (c TCol[T]) LeCol(o TCol[T]) Expr
- func (c TCol[T]) Lt(v T) Expr
- func (c TCol[T]) LtCol(o TCol[T]) Expr
- func (c TCol[T]) Max() TCol[T]
- func (c TCol[T]) Mean() TCol[float64]
- func (c TCol[T]) Median() TCol[float64]
- func (c TCol[T]) Min() TCol[T]
- func (c TCol[T]) Mul(v T) TCol[T]
- func (c TCol[T]) MulCol(o TCol[T]) TCol[T]
- func (c TCol[T]) NUnique() TCol[int64]
- func (c TCol[T]) Ne(v T) Expr
- func (c TCol[T]) NeCol(o TCol[T]) Expr
- func (c TCol[T]) Neg() TCol[T]
- func (c TCol[T]) NullCount() TCol[int64]
- func (c TCol[T]) Over(keys ...string) TCol[T]
- func (c TCol[T]) Product() TCol[T]
- func (c TCol[T]) Quantile(q float64) TCol[float64]
- func (c TCol[T]) Reverse() TCol[T]
- func (c TCol[T]) RollingMax(windowSize, minPeriods int) TCol[T]
- func (c TCol[T]) RollingMean(windowSize, minPeriods int) TCol[float64]
- func (c TCol[T]) RollingMin(windowSize, minPeriods int) TCol[T]
- func (c TCol[T]) RollingStd(windowSize, minPeriods int) TCol[float64]
- func (c TCol[T]) RollingSum(windowSize, minPeriods int) TCol[T]
- func (c TCol[T]) RollingVar(windowSize, minPeriods int) TCol[float64]
- func (c TCol[T]) Shift(periods int) TCol[T]
- func (c TCol[T]) Skew() TCol[float64]
- func (c TCol[T]) Slice(off, length int) TCol[T]
- func (c TCol[T]) Sort(descending bool) TCol[T]
- func (c TCol[T]) Std() TCol[float64]
- func (c TCol[T]) Sub(v T) TCol[T]
- func (c TCol[T]) SubCol(o TCol[T]) TCol[T]
- func (c TCol[T]) Sum() TCol[T]
- func (c TCol[T]) Tail(n int) TCol[T]
- func (c TCol[T]) Unique() TCol[T]
- func (c TCol[T]) Var() TCol[float64]
- type UnaryNode
- type UnaryOp
- type WhenBuilder
- type WhenThenBuilder
- type WhenThenNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Columns ¶
Columns returns the set of distinct column names referenced by e. OverNode partition keys count as references even though they don't appear as ColNode children.
func ContainsAgg ¶
ContainsAgg reports whether e contains an AggNode anywhere in its subtree.
func OutputName ¶
OutputName returns the inferred name of the expression's output column. An Alias defines the name explicitly; otherwise the first referenced column name is used (mirroring polars).
Types ¶
type BinaryNode ¶
BinaryNode combines two sub-expressions with an operator.
func (BinaryNode) String ¶
func (b BinaryNode) String() string
type Expr ¶
type Expr struct {
// contains filtered or unexported fields
}
Expr is the public expression value. It wraps an internal Node and carries fluent builder methods.
func Coalesce ¶
Coalesce returns the first non-null value across the given expressions at each row. Mirrors polars' pl.coalesce(...).
func Col ¶
Col returns an expression that references a column by name.
The name is resolved at execution time against the frame's schema, so a typo or missing column surfaces when the lazy plan runs, not when the expression is built. Col is the starting point of almost every expression: arithmetic, predicates, string methods, aggregates, and window functions all chain off of it.
Parameters ¶
- name: column name in the frame under evaluation.
Returns ¶
An Expr that, at eval time, produces the referenced column.
Examples ¶
Build a predicate from a column:
expr.Col("age").Gt(expr.LitInt64(18))
Project and alias:
expr.Col("salary").Mul(expr.LitFloat64(12)).Alias("annual")
Use in a full pipeline:
df.Lazy().
Filter(expr.Col("salary").Gt(expr.LitInt64(100_000))).
GroupBy("dept").
Agg(expr.Col("salary").Mean().Alias("avg"))
func ConcatStr ¶
ConcatStr concatenates the string representations of each expr row-wise, using sep as the delimiter. Nulls in any input propagate to the output (strictest polars behaviour). Mirrors pl.concat_str(..., separator=sep).
func IntRange ¶
IntRange returns a new int64 Series of [start, end) with the given step. Produces a length-mismatched column which callers typically wrap in pl.int_range(...).alias("idx"). step may not be zero.
func Lit ¶
Lit is a type-inferring literal constructor.
The Go type of v decides the dtype: `int` / `int32` / `int64` become i64, `float32` / `float64` become f64, plus `bool`, `string`, and `nil` (typed null). Anything else panics, so reach for LitInt64 / LitFloat64 / LitString when the exact dtype matters for a mixed-type comparison.
Parameters ¶
- v: Go scalar value; see above for supported types.
Returns ¶
An Expr producing the literal when evaluated.
Examples ¶
Scalar literals inline:
expr.Col("qty").Mul(expr.Lit(2)) // int inferred as i64
expr.Col("tag").Eq(expr.Lit("priority")) // string literal
expr.Lit(nil) // typed null
Prefer a typed constructor when the RHS dtype matters:
expr.Col("score_f64").Gt(expr.LitFloat64(80)) // f64 != i64(80)
func LitFloat64 ¶
LitFloat64 returns a typed float64 scalar literal. See LitInt64 for when to prefer this over Lit.
func LitInt64 ¶
LitInt64 returns a typed int64 scalar literal.
Use Lit for Go-idiomatic type inference; reach for LitInt64 directly when you need to pin the dtype (e.g. comparing against an i64 column where the Go source would otherwise infer int).
Example:
expr.Col("score").Gt(expr.LitInt64(80))
func LitNull ¶
LitNull returns a null literal carrying dt as its declared dtype. Useful inside When / Coalesce where the branches must agree on a concrete type.
Example:
expr.Coalesce(expr.Col("primary"), expr.LitNull(dtype.String()))
func LitOf ¶
LitOf is a type-safe variant of Lit. The literal's Go type must be one of the supported scalar types; non-scalar values fail at build time rather than panicking at evaluation.
expr.LitOf(int64(2)) // or expr.LitOf[int64](2)
expr.LitOf("USD") // T inferred as string
func Not ¶
Not, All, Any are top-level helpers that read well in predicate chains:
expr.All(a.Gt(0), b.Lt(10), c.IsNotNull())
expr.Any(a.IsNull(), b.Eq(0))
expr.Not(a.Eq("x"))
Not is a thin passthrough; All / Any fold a variadic list into And / Or chains.
func WithChildren ¶
WithChildren constructs a new expression with the given children replacing the originals. Panics if len(children) does not match the expected arity of the node.
func (Expr) Add ¶
Add returns `e + other`, computed element-wise.
Null propagation: if either operand is null at a row, the result is null. Numeric dtype promotion mirrors polars (i64 + f64 → f64).
Parameters ¶
- other: right-hand side Expr; must be numeric.
Returns ¶
An Expr producing the sum.
Examples ¶
// Two columns:
expr.Col("base").Add(expr.Col("bonus"))
// Column + scalar:
expr.Col("price").Add(expr.LitFloat64(1.0))
See also Expr.AddLit for scalar RHS, Expr.Sub, Expr.Mul, Expr.Div.
func (Expr) AddLit ¶
AddLit is sugar for e.Add(Lit(v)). Use it when the RHS is a plain Go value so you don't have to write the constructor twice.
func (Expr) Alias ¶
Alias renames the expression's output column.
The renamed expression is still a valid right-hand side for another op, so aliases can chain. Repeated Alias calls collapse: `e.Alias("a").Alias("b")` is equivalent to `e.Alias("b")`.
Parameters ¶
- name: new column name for the result.
Returns ¶
An Expr that renames this one's output.
Examples ¶
// Derive a yearly salary column:
expr.Col("salary").Mul(expr.LitFloat64(12)).Alias("annual")
// Assign a human-friendly name to a predicate:
expr.Col("age").Ge(expr.LitInt64(18)).Alias("adult")
func (Expr) And ¶
And returns the element-wise logical AND of two boolean expressions. Null in either operand yields null.
Parameters ¶
- other: boolean Expr.
Returns ¶
A boolean Expr.
Examples ¶
expr.Col("age").Ge(expr.LitInt64(18)).And(
expr.Col("active").Eq(expr.LitBool(true)),
)
func (Expr) ApproxNUnique ¶
ApproxNUnique estimates the number of distinct values using HLL.
func (Expr) BackwardFill ¶
BackwardFill propagates the next non-null value backward into nulls.
func (Expr) Div ¶
Div returns e / other. Integer operands divide as integers; mix a float operand to force float output.
func (Expr) EWMMean ¶
EWMMean / EWMVar / EWMStd return the adjusted exponentially- weighted moving statistic with the given alpha. Alpha must be in (0, 1]; values outside trigger a runtime error at eval time.
func (Expr) Entropy ¶
Entropy returns Shannon entropy in the given base (natural log by default when base=0 or omitted in callers).
func (Expr) Eq ¶
Eq returns the element-wise equality test (`e == other`).
The result is a boolean Expr suitable for [lazy.LazyFrame.Filter] or as the predicate of When.
Parameters ¶
- other: right-hand side Expr; dtypes must be compatible.
Returns ¶
A boolean Expr.
Examples ¶
expr.Col("status").Eq(expr.LitString("active"))
// Compose predicates:
expr.Col("dept").Eq(expr.LitString("eng")).
And(expr.Col("active").Eq(expr.LitBool(true)))
See also Expr.Ne, Expr.EqLit.
func (Expr) FillNan ¶
FillNan replaces NaN values in float columns with v. Integer and string columns are returned unchanged (mirrors polars).
func (Expr) FillNull ¶
FillNull replaces nulls with the given scalar value. The value is wrapped in a literal Expr internally so the planner can fold.
func (Expr) FillNullExpr ¶
FillNullExpr replaces nulls with the result of another expression (polars allows a full expression here).
func (Expr) ForwardFill ¶
ForwardFill propagates the last non-null value forward into nulls. limit=0 means unlimited; otherwise at most limit consecutive nulls are filled before a run is left untouched.
func (Expr) Gt ¶
Gt returns the element-wise greater-than test (`e > other`).
Parameters ¶
- other: right-hand side Expr; dtypes must be comparable.
Returns ¶
A boolean Expr.
Examples ¶
// Filter rows where age > 18:
df.Lazy().Filter(expr.Col("age").Gt(expr.LitInt64(18)))
// Chain on another op:
expr.Col("salary").Gt(expr.LitFloat64(100_000)).Alias("bulk")
func (Expr) Hash ¶
Hash returns a stable 64-bit hash of the expression structure. Used for common subexpression elimination.
func (Expr) HashValues ¶
HashValues returns a per-row FNV-64a hash as a uint64 column. Nulls propagate to nulls. Named HashValues (not Hash) because Expr.Hash already exists on the structural-hash side for CSE.
func (Expr) IsDuplicated ¶
IsDuplicated is true where the value occurs more than once.
func (Expr) IsFirstDistinct ¶
IsFirstDistinct / IsLastDistinct mark the first/last occurrence of each distinct value.
func (Expr) IsIn ¶
IsIn returns a boolean predicate: true iff e is one of `values`. Implemented via an OR-chain of equality; for a handful of values this is as fast as a hash lookup, and avoids a new evaluator node.
func (Expr) IsLastDistinct ¶
func (Expr) IsNotNull ¶
IsNotNull returns a boolean expression that is true where the input is not null.
func (Expr) Node ¶
Node returns the underlying AST node for pattern matching by internal consumers (the evaluator and the optimizer).
func (Expr) Over ¶
Over wraps e so it is evaluated separately per group defined by keys, then broadcast back to the original row order. Mirrors polars' expr.over(*keys).
func (Expr) Rank ¶
Rank returns a float64 rank column using the given method. method is the polars-style string: "average", "min", "max", "dense", "ordinal".
func (Expr) RollingMax ¶
func (Expr) RollingMean ¶
func (Expr) RollingMin ¶
func (Expr) RollingStd ¶
func (Expr) RollingSum ¶
RollingSum / Mean / Min / Max / Std / Var apply a fixed-size window reduction. minPeriods=0 defaults to windowSize. Mirrors polars' rolling_* Expr methods.
func (Expr) RollingVar ¶
func (Expr) Round ¶
Round rounds to the given number of decimal places (0 = integer). Integers pass through unchanged.
func (Expr) Sort ¶
Sort returns the sorted values of the column. Ascending is the polars default; pass descending=true for reverse order.
func (Expr) Str ¶
Str returns a string-ops view over e. This mirrors polars' `col("x").str.*` namespace: every method returns a new Expr that plugs back into the normal expression algebra.
Allocation-free wrapper; the actual work happens inside the kernel that evaluates the returned Expr.
Examples ¶
// Case fold:
expr.Col("name").Str().ToUpper()
// Regex predicate:
expr.Col("email").Str().ContainsRegex(`@example\.com$`)
// Chain with the list namespace:
expr.Col("csv").Str().SplitExact(",").List().Len()
type FunctionNode ¶
type FunctionNode struct {
Name string
Args []Expr
// Params carries non-Expr scalar arguments (e.g. the decimals arg
// of round, or the low/high bounds of clip). Encoded as opaque any
// so the evaluator can type-assert per function.
Params []any
}
FunctionNode applies a named unary/multi-arg function to one or more inner expressions. Keeps the AST small while letting us add new scalar kernels (abs, sqrt, log, round, floor, ceil, …) without a new Node type each time.
The name is the canonical lower-case function name (polars-style). The evaluator and optimiser switch on Name to dispatch.
func (FunctionNode) String ¶
func (f FunctionNode) String() string
type IsNullNode ¶
IsNullNode tests for null, or (with Negate) non-null.
func (IsNullNode) String ¶
func (n IsNullNode) String() string
type ListOps ¶
type ListOps struct {
// contains filtered or unexported fields
}
ListOps is the expression-level mirror of series.ListOps. Reach it via Expr.List(); every method returns a fresh Expr so the kernel runs at evaluation time.
type LitNode ¶
type LitNode struct {
DType dtype.DType
// Value is a typed Go value. Supported types: int64, float64, bool,
// string. Use the Lit* constructors to build a LitNode safely.
Value any
}
LitNode is a typed literal value.
type Node ¶
Node is the tag interface for AST nodes. Users do not construct Nodes directly; they work with Expr values returned by constructors.
type OverNode ¶
OverNode wraps an inner expression with a list of partition keys, turning `pl.col("x").sum()` into `pl.col("x").sum().over("k")`: the reduction is computed per-group and broadcast back to every row of the original frame.
type Scalar ¶
Scalar is the set of Go scalar types that can be promoted to a literal expression. It mirrors the cases the untyped Lit function accepts, but as a type constraint so generic helpers can be compile-time checked.
type StrOps ¶
type StrOps struct {
// contains filtered or unexported fields
}
StrOps is the expression-level mirror of series.StrOps: a namespace of string-column operations reachable from an Expr via .Str(). Methods return new Exprs so they compose with the rest of the algebra; the concrete kernel runs when eval dispatches on the FunctionNode's Name.
Every name here is prefixed with "str." so the eval switch can separate string kernels from the general function table. Polars uses the same mental model: `pl.col("x").str.contains(...)` is a namespaced op, not a global function.
func (StrOps) Contains ¶
Contains tests each row for a literal substring needle. Empty needle matches every non-null row; use StrOps.ContainsRegex for regex behaviour.
Examples ¶
// "foo" anywhere in the value:
expr.Col("msg").Str().Contains("foo")
func (StrOps) ContainsRegex ¶
ContainsRegex runs a compiled regexp against each row and returns a boolean Expr.
Examples ¶
// Email addresses on example.com:
expr.Col("email").Str().ContainsRegex(`@example\.com$`)
func (StrOps) CountMatches ¶
CountMatches counts non-overlapping occurrences of needle per row.
func (StrOps) EndsWith ¶
EndsWith is a byte-suffix predicate. See StrOps.StartsWith.
func (StrOps) Find ¶
Find returns the byte offset of the first occurrence of needle, or -1 when missing.
func (StrOps) Head ¶
Head returns the first n characters (runes) of each row. Negative n means "all but the last |n|".
func (StrOps) Like ¶
Like is a SQL-style wildcard predicate.
Wildcards ¶
- `%` matches any sequence of characters (including empty)
- `_` matches exactly one character
- `\` escapes the following character literal
Examples ¶
// Names starting with "a" followed by anything:
expr.Col("name").Str().Like("a%")
// Three-letter codes starting with "F":
expr.Col("code").Str().Like("F__")
func (StrOps) NotLike ¶
NotLike is the logical negation of StrOps.Like.
func (StrOps) ReplaceAll ¶
ReplaceAll swaps every occurrence of old.
func (StrOps) Slice ¶
Slice is a two-argument variant: start, length. Length -1 means "to end". Mirrors polars str.slice.
func (StrOps) SplitExact ¶
SplitExact splits each cell by sep and returns a list column (dtype List<String>). Compose with the list.* namespace, e.g. `col("x").Str().SplitExact(",").List().Len()`.
func (StrOps) StartsWith ¶
StartsWith is a byte-prefix predicate. Compare the row's raw bytes against prefix; nulls stay null.
Examples ¶
expr.Col("sku").Str().StartsWith("US-")
func (StrOps) StripPrefix ¶
StripPrefix drops one occurrence of prefix from the start of each row; unmatched rows pass through unchanged.
func (StrOps) StripSuffix ¶
StripSuffix is the symmetric counterpart.
type StructOps ¶
type StructOps struct {
// contains filtered or unexported fields
}
StructOps is the expression-level mirror of series.StructOps.
type TCol ¶
TCol is a typed column reference. It wraps an Expr with a phantom type that represents the column's Go-level scalar type, so the comparison/arithmetic helpers can take a bare T instead of an Expr wrapped around a Lit.
expr.C[int64]("qty").Gt(2).Alias("bulk")
The type parameter is an intent hint, not a proof. If the runtime schema disagrees, evaluation panics with the same message that the untyped path produces. Use C when the column dtype is statically known; stick with Col when it is dynamic (config-driven, user-supplied, etc.).
func Int ¶
Int, Float, Str, Bool, Int32, Float32 are ergonomic aliases for the common C[T] instantiations. They read more naturally at the call site: `expr.Int("qty").Gt(2)` vs `expr.C[int64]("qty").Gt(2)`.
func (TCol[T]) Add ¶
Add, Sub, Mul, Div take a literal of the column's type and preserve T on the output. Promotion rules (e.g. int + float -> float) are not expressible at the type level; callers that need cross-type arithmetic should drop to the embedded Expr and .Cast explicitly.
func (TCol[T]) AddCol ¶
AddCol, SubCol, MulCol, DivCol combine two same-typed columns and preserve T on the output.
func (TCol[T]) ApproxNUnique ¶
func (TCol[T]) As ¶
As renames the expression output, returning a typed column so further typed operations can chain. Alias is a drop-in synonym that matches the untyped Expr's naming.
func (TCol[T]) BackwardFill ¶
func (TCol[T]) Between ¶
Between returns a boolean expression: lo <= c <= hi. Polars' pl.col().is_between(lo, hi) equivalent.
func (TCol[T]) CastFloat64 ¶
func (TCol[T]) CastInt64 ¶
CastInt64, CastFloat64, CastBool, CastString are convenience wrappers over CastTo that also re-tag the returned TCol so the type parameter stays meaningful.
func (TCol[T]) CastString ¶
func (TCol[T]) CastTo ¶
CastTo drops the typed wrapper and coerces to the target dtype at evaluation. Use this to bridge typed columns of different T into a common dtype before combining them.
func (TCol[T]) Eq ¶
Eq, Ne, Lt, Le, Gt, Ge compare against a literal of the column's type. They return an untyped boolean Expr because downstream use (And/Or/Filter) is dtype-agnostic.
func (TCol[T]) EqCol ¶
EqCol, NeCol, LtCol, LeCol, GtCol, GeCol compare two typed columns of the same T. Mixed-type comparisons go through the untyped API: `c.Expr.Gt(other.Expr)`.
func (TCol[T]) FillNull ¶
FillNull replaces nulls with a literal of the column's type. For cross-type fill (e.g. fill an int64 column with a float default) use the embedded Expr.FillNull(any).
func (TCol[T]) ForwardFill ¶
func (TCol[T]) IsIn ¶
IsIn returns a boolean expression: c in {values}. Membership is evaluated with equality on the column's scalar type.
func (TCol[T]) IsNull ¶
IsNull and IsNotNull return boolean expressions. Null checks apply to every dtype, so the output is untyped for downstream logic.
func (TCol[T]) Mean ¶
Mean always promotes to float64. Count and NullCount always produce int64. Median/Std/Var similarly promote to float64 for every numeric input.
func (TCol[T]) Neg ¶
Neg negates the column (valid for numeric dtypes; behaviour on non-numeric is inherited from the untyped Neg).
func (TCol[T]) Over ¶
Over broadcasts an aggregation over the given partition keys. The output keeps T because the underlying aggregation's dtype is preserved across the partition.
func (TCol[T]) RollingMax ¶
func (TCol[T]) RollingMin ¶
func (TCol[T]) RollingSum ¶
RollingSum/Min/Max preserve T. RollingMean/Std/Var promote to float64 since they introduce fractional values even for integer inputs.
type WhenBuilder ¶
type WhenBuilder struct {
// contains filtered or unexported fields
}
WhenBuilder captures a predicate awaiting Then().
func When ¶
func When(pred Expr) WhenBuilder
When starts a conditional expression, polars-style. Always chain exactly one WhenBuilder.Then and one WhenThenBuilder.Otherwise; the resulting Expr carries the promoted dtype of both branches.
Example:
// Clamp salary to a grade bucket.
bucket := expr.When(expr.Col("salary").Gt(expr.LitInt64(150_000))).
Then(expr.LitString("senior")).
Otherwise(
expr.When(expr.Col("salary").Gt(expr.LitInt64(80_000))).
Then(expr.LitString("mid")).
Otherwise(expr.LitString("junior")),
).Alias("grade")
func (WhenBuilder) Then ¶
func (w WhenBuilder) Then(v Expr) WhenThenBuilder
Then records the value taken when the predicate is true.
type WhenThenBuilder ¶
type WhenThenBuilder struct {
// contains filtered or unexported fields
}
WhenThenBuilder captures pred+then awaiting Otherwise().
func (WhenThenBuilder) Otherwise ¶
func (w WhenThenBuilder) Otherwise(v Expr) Expr
Otherwise closes the conditional and returns an Expr.
type WhenThenNode ¶
WhenThenNode is a conditional: when(pred).then(a).otherwise(b).
func (WhenThenNode) String ¶
func (w WhenThenNode) String() string