← Back to Pull requests

fix(rust): Report List dtype in schema for Expr.quantile with multiple quantiles #29084

Closed
unknown closed this pull request without merging on Sep 02, 2026 14:20 UTC
View on GitHub
unknown unknown commented on Sep 01, 2026 20:20 UTC
Author

Summary

Expr.quantile() accepts either a single quantile (returns a scalar) or a list of quantiles (returns list[f64], one value per requested quantile), exactly as documented in its own docstring. The physical evaluator honors this correctly, but collect_schema() always predicted the scalar dtype for the list case, producing a schema that does not match the actual materialized result:

lf = pl.LazyFrame({"a": [1.0, 2.0, 3.0]})
q = lf.select(pl.col("a").quantile([0.1, 0.5, 0.9]))

q.collect_schema()   # Schema({'a': Float64})        <- wrong
q.collect().schema    # Schema({'a': List(Float64)})  <- actual, correct result

Closes #29030.

Root cause

Expr.quantile(quantile, method) builds a binary function node (dsl/mod.rs): field 0 is the target column, field 1 is the quantile-probabilities expression (List(Float64) when a Python list is passed, scalar Float64 otherwise).

Schema inference for Quantile called moment_dtype(), which goes through map_dtype() and reads only fields[0]. It never inspects fields[1], the one thing that actually determines whether the output is scalar or list, so it always predicted the scalar shape.

The physical dispatch (dispatch/misc.rs::quantile) gets this right — it branches on fields[1]'s dtype:

match quantile.dtype() {
    DataType::List(_) => { /* ... */ input.quantiles_reduce(&v, method) /* -> List */ },
    _ => { /* ... */ input.quantile_reduce(q, method) /* -> scalar */ },
}

confirming the schema function is the side that's wrong.

Fix

Added FieldsMapper::quantile_dtype(), following the same two-field-read convention already used by the neighboring pow_dtype/log_dtype helpers in the same file: compute the moment dtype as before via the existing moment_dtype(), then wrap it in List when fields[1]'s dtype is List, mirroring exactly the branch the physical dispatch takes on that same field. Uses Field::coerce, the same method already used by nested_sum_type/nested_mean_median_type in this file, so no new patterns are introduced.

Only checking DataType::List (not Array) is deliberate — it matches exactly what the physical dispatch checks, so schema and runtime stay in lockstep.

rolling_quantile/rolling_quantile_by (a different, always-scalar calling convention) are untouched and out of scope.

Test plan

  • Reproduced the issue's exact example against an unpatched build, confirmed the mismatch, confirmed it's gone after the fix.

  • Added test_quantile_list_schema_29030 in py-polars/tests/unit/operations/test_statistics.py, covering both the list case (schema now matches, and is List(Float64)) and the scalar case (must not regress to always wrapping in List).

  • Ran the full existing quantile test surface (test_statistics.py, test_aggregations.py, rolling quantile tests in test_rolling.py x2) — 78 passed, confirming the rolling-quantile arms are unaffected.

  • make test — 18949 passed, 233 skipped, 7 xfailed.

  • make lint (ruff, pyrefly, mypy, typos) — clean.

  • cargo clippy -p polars-plan --all-targets --all-features — zero warnings from the changed code.

  • cargo fmt -p polars-plan --check — clean.
  • Diff: 403 lines (+302 / -101) across 5 files Reviewer: BitWeaverDev Review duration: 1080m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 403 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.359
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #29084"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.7% · Safe to merge
    17.7%
    Repository