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 withparse_expr.SeriesRef: a typed column-name reference. Used byExprvariants and by callers building expressions programmatically.EvalContext: the evaluation environment — bindings for local variables (the@local_varsyntax in pandas eval) plus theRuntimePolicy/EvidenceLedgerfrom fp-runtime for decision recording.ExprError: failure modes (parse error, unknown column, type mismatch, division by zero, …).
§Evaluation entry points
Direct AST eval:
evaluate: evaluate anExpragainst a Series-like input.evaluate_on_dataframe: bind columns from a DataFrame as identifiers and evaluate.evaluate_on_dataframe_with_locals: same, plus an external@localbinding map.filter_dataframe_on_expr/filter_dataframe_on_expr_with_locals: shortcut fordf[df.eval(expr)]— the boolean-mask filter pattern.
String entry points (parse-then-eval):
eval_str/eval_str_with_locals: pandasdf.eval(string)— returns a new Series / DataFrame column.query_str/query_str_with_locals: pandasdf.query(string)— returns the row-filtered DataFrame.parse_expr: the standalone parser if you only want the AST.
§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 throughEvalContext.
Structs§
- Delta
- An append hint identifying new rows in a base series.
- Eval
Context - Materialized
View - The last successful evaluation and its source context.
- Series
Ref
Enums§
- Between
Inclusive - Eval
Value - What pandas’
DataFrame.evalanswers 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
- Expr
Duplicate Keep - Expr
Error
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§
- Data
Frame Expr Ext - Extension trait that adds
eval()andquery()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::Scalarfor one naming no column, evaluated once over a one-row anchor whatever the frame’s length, elseEvalValue::Series. - eval_
value_ str_ with_ locals eval_value_on_dataframe_with_localsof 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
ExprAST. - query_
str - Filter a DataFrame using a string expression.
- query_
str_ with_ locals