Skip to main content

Crate fp_expr

Crate fp_expr 

Source
Expand description

Expression engine for frankenpandas — implements pandas DataFrame.eval() / DataFrame.query() semantics for Rust callers and provides the underlying Expr AST + parser / evaluator that the rest of the workspace can build on.

§Why

Pandas users write things like:

df.query("price > 100 and category == 'A'")
df.eval("margin = revenue - cost")

This crate gives Rust callers the equivalent: df.query(...), df.eval(...), with a parsed Expr AST you can build programmatically or via the string parser.

§Public surface

  • Expr: the expression AST. Built either by hand (Expr::Series, Expr::Add, Expr::Sub, Expr::Local, etc.) or by parsing a pandas-style string with parse_expr.
  • SeriesRef: a typed column-name reference. Used by Expr variants and by callers building expressions programmatically.
  • EvalContext: the evaluation environment — bindings for local variables (the @local_var syntax in pandas eval) plus the RuntimePolicy / EvidenceLedger from fp-runtime for decision recording.
  • ExprError: failure modes (parse error, unknown column, type mismatch, division by zero, …).

§Evaluation entry points

Direct AST eval:

String entry points (parse-then-eval):

§DataFrame extension trait

DataFrameExprExt adds df.eval(expr) / df.query(expr) method-style entry points on DataFrame so users can call them fluently after use fp_expr::DataFrameExprExt;.

§Incremental views

MaterializedView caches the last successful result and its input context. Delta carries an append hint. Updates validate that hint and evaluate against the supplied complete context before replacing the cache. Full re-evaluation is currently intentional: public view fields and changed input metadata make expression shape alone insufficient to prove that cached rows can be reused.

§Cross-crate relationships

  • fp-types (Scalar), fp-columnar (ComparisonOp), fp-index (Index), fp-frame (Series, DataFrame, FrameError) are all consumed.
  • fp-runtime (RuntimePolicy, EvidenceLedger) provides the optional decision-policy hook threaded through EvalContext.

Structs§

Delta
An append hint identifying new rows in a base series.
EvalContext
MaterializedView
The last successful evaluation and its source context.
SeriesRef

Enums§

BetweenInclusive
EvalValue
What pandas’ DataFrame.eval answers for an expression without an assignment: the Series an expression over columns makes or, for one naming no column (1 + 2, 3 * "ab", @x + 1), its one value, computed once. fp broadcast that value to every row (br-frankenpandas-2blaf).
Expr
ExprDuplicateKeep
ExprError

Constants§

MAX_BRACKET_NESTING
CPython’s tokenizer refuses more than 200 nested brackets, which pandas raises as tokenize.TokenError: too many nested parentheses.
MAX_EXPR_DEPTH
The deepest expression tree the parser builds (a leaf is depth 1).

Traits§

DataFrameExprExt
Extension trait that adds eval() and query() methods directly to DataFrame.

Functions§

col
Helper to construct a column reference expression Expr::Series.
eval_str
Evaluate a string expression against a DataFrame and return a Series.
eval_str_with_locals
eval_value_on_dataframe_with_locals
pandas’ DataFrame.eval (without an assignment) of a parsed expression: EvalValue::Scalar for one naming no column, evaluated once over a one-row anchor whatever the frame’s length, else EvalValue::Series.
eval_value_str_with_locals
eval_value_on_dataframe_with_locals of an expression string.
evaluate
evaluate_on_dataframe
evaluate_on_dataframe_with_locals
filter_dataframe_on_expr
filter_dataframe_on_expr_with_locals
lit
Helper to construct a literal scalar expression Expr::Literal.
parse_expr
Parse a string expression into an Expr AST.
query_str
Filter a DataFrame using a string expression.
query_str_with_locals