Skip to content

feat(polars): Wire fused streaming aggregation from polars_engine into PolarsBackend #532

Open

Description

@JohnnyWilson16

Summary

Currently, PolarsBackend.profile() in src/freshdata/_core/backends.py returns a hollow ProfileReport for pl.LazyFrame inputs, reporting hardcoded zeroes for row_count, null_count, and null_ratio:

# src/freshdata/_core/backends.py:112-126
def profile(self, df: pl.DataFrame | pl.LazyFrame) -> ProfileReport:
    schema = df.collect_schema() if isinstance(df, pl.LazyFrame) else df.schema
    cols = {}
    for name, dtype in schema.items():
        role = "numeric" if dtype.is_numeric() else "categorical"
        cols[name] = ColumnProfile(
            name=name,
            inferred_role=role,
            null_count=0,       # <-- Hardcoded zero
            null_ratio=0.0,     # <-- Hardcoded zero
            unique_count=0,
            sample_values=(),
        )
    row_count = 0 if isinstance(df, pl.LazyFrame) else len(df)
    return ProfileReport(row_count=row_count, column_count=len(schema), columns=cols)

However, src/freshdata/polars_engine.py:126-159 already implements a high-performance, single-pass streaming aggregation query:

stat_exprs: list[pl.Expr] = [pl.len().alias("__total_rows")]
# ... builds null_count, mean, median, quantiles ...
stats = lf.select(stat_exprs).collect(engine="streaming").row(0, named=True)

Motivation & Impact

  • User Experience (UX): Users profiling out-of-core Parquet or Arrow datasets via pl.scan_parquet(...) receive zero null statistics and empty metrics.
  • Developer Experience (DX): PolarsBackend.suggest_plan() in _core/backends.py does not compute precomputed median/IQR thresholds for LazyFrame like polars_engine.py does.

Proposed Solution

  1. Integrate the streaming expression generator from polars_engine.py into PolarsBackend.profile() and PolarsBackend.suggest_plan().
  2. Ensure that pl.LazyFrame inputs are profiled using a single 1-row aggregation pass (lf.select(stat_exprs).collect(engine="streaming")) rather than returning zeroed placeholders.
  3. Guarantee that apply_plan continues to compile elementwise expressions without triggering .collect().

Acceptance Criteria

  • fd.profile(lazy_df) returns accurate null_count, null_ratio, and row_count on pl.LazyFrame.
  • tests/test_backend_honesty.py continues to pass (no .collect() during apply_plan).
  • Benchmark memory profile passes without exceeding streaming RSS thresholds.

👋 Want to work on this issue?
Comment /assign below to claim it! Check out the First Contribution Guide for setup instructions.

Activity

  1. added
    enhancement
    good first issue
    help wanted
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions