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 + Delta: the foundation for incremental eval-derived columns. A MaterializedView caches the last result and the input fingerprint; on next call, only re-evaluates when inputs change. Delta records what changed for downstream consumers.

§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
A delta represents new rows appended to a base series.
EvalContext
MaterializedView
Cached result of a previous full evaluation, used as base for incremental updates.
SeriesRef

Enums§

BetweenInclusive
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
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