feat(pivotp): --agg quantile@<p> (alias q@<p>) with linear interpolation#3842
Merged
Conversation
Adds per-group quantile aggregation in both pivot and group-by modes via Polars' Expr::quantile with QuantileMethod::Linear (matches numpy/pandas/ scipy defaults). Probability p must be a float in [0, 1]; malformed values hit a precise pre-match validation error rather than the generic "Invalid pivot aggregation function". No new dependency. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 10 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new per-group quantile aggregation option to the pivotp command (--agg quantile@<p> with alias q@<p>) implemented via Polars’ linear-interpolated quantile, including targeted validation errors and integration tests.
Changes:
- Document
quantile@<p>/q@<p>inpivotphelp text. - Add
quantile@<p>parsing/validation and wire it into both pivot-mode and group-by-mode aggregation expression building. - Add integration tests covering correct results, alias behavior, invalid probabilities, and group-by mode.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/cmd/pivotp.rs |
Adds parsing/validation for quantile@<p> / q@<p> and constructs Polars quantile expressions in pivot + group-by modes. |
tests/test_pivotp.rs |
Adds new integration tests verifying quantile output, alias equivalence, invalid input rejection, and group-by behavior. |
- Refactor both quantile match arms to `s if let Some(p) = parse_quantile_agg(s)`, parsing once and removing the .unwrap() + safety comment. - Restore `mut` on the second cmd binding in pivotp_quantile_invalid_p_rejected (a hook had snake_cased it to `cmd_2` and dropped `mut`, breaking the build). Addresses Copilot review on #3842. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Update tests/test_pivotp.rs by renaming the local variable `cmd2` to `cmd_2` and adjusting its usages (args, assert_err, output_stderr). This clarifies naming and keeps the test consistent with the surrounding code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pivotpvia a new--agg quantile@<p>aggregation function (aliasq@<p>), wherepis a float in[0, 1]. Examples:--agg quantile@0.95,--agg q@0.5.Expr::quantilewithQuantileMethod::Linear— exact, fast, and matches numpy/pandas/scipy/stats --quantile-method lineardefaults. No new dependency.quantile@p@method) is intentionally deferred — the surface stays minimal until someone asks for it.(Supersedes #3841, which was auto-closed when the branch was renamed from
pivotp-quantlleto fix a typo.)Test plan
cargo build --locked --bin qsv -F all_features— cleancargo t pivotp -F all_features— 62/62 passcargo clippy -F all_features— no warningstests/test_pivotp.rs:pivotp_quantile_p95_agg— pivot mode,--agg quantile@0.95, asserts exact linear-interpolated p95pivotp_q_alias_p50_equals_median—--agg q@0.5produces byte-identical output to--agg medianon the standard fixturepivotp_quantile_invalid_p_rejected—quantile@1.5,q@-0.1, andquantile@abcall exit non-zero with "Invalid quantile probability" in stderrpivotp_quantile_groupby_mode— group-by mode (no<on-cols>),--agg q@0.25, asserts Q1 per group🤖 Generated with Claude Code