Skip to content

feat(viz): stat_count / stat_identity bar layout core (PLOT-GG-001 recut B2) - #7040

Merged
noahgift merged 7 commits into
mainfrom
recut/b2-stat-count
Nov 14, 2026
Merged

noahgift merged 7 commits into
mainfrom
recut/b2-stat-count

Conversation

@noahgift

Copy link
Copy Markdown
Member

Second bars slice of the #6938 re-cut. It was cut on #7021 (B1, position core); #7021 has since merged to main as fe2fcb0, and main was merged into this branch (no rebase), so this PR targets main.

Provenance

New in this slice

  • Doc lines 13-16. The old note called the discrete-scales lane a parallel PR and said GGPlot::layout() calls bar_layout_in. At this slice scale_discrete is on main and nothing in the grammar calls the bar core, so the note now says that.
  • Unit tests. Expected values are ggplot_build() output from R 4.6.2 + ggplot2 4.0.3, LC_COLLATE=C. R ran on its own host, and no cargo ran there.
    • bar_counts_each_level_in_c_order_with_prop_over_the_group: geom_bar(), one group.
    • bar_with_fill_ranks_x_first_and_fills: aes(fill) + position_fill().
    • bar_with_layer_fill_ranks_fill_first_and_counts_per_panel: fill on the layer, two facet panels.
    • col_keeps_row_order_and_wide_bars_widen_the_x_range: geom_col(width = 1.4) with negative y.
    • bad_columns_are_refused_naming_the_column: every BarError variant and its Display text.
    • a_repeated_level_keeps_its_first_position_and_an_unknown_value_is_nan.

Scope

The bar layout core only: no contract, fixture, ggplot.rs wiring or rendering. Nothing reachable from GGPlot changes. Wiring, contracts and fixtures come in the later bar/col slices.

Review findings F4-F6 (#6938 round 5)

Gates (x86_64 build host, own clone at 93d8a38, origin/main = fe2fcb0; rc read from each command, never through a pipe)

gate rc result
cargo fmt --all -- --check 0
cargo clippy -p aprender-viz --lib --tests -- -D warnings 0
cargo test -p aprender-viz 0
cargo nextest run --profile ci -p aprender-viz --lib --tests 0 913 run, 913 passed
cargo test -p aprender-contracts --lib 0 2382 passed
scripts/contracts_gate.sh 0 8 of 8 steps ran, 0 failed
python3 scripts/ci/fail_fast.py ids --base origin/main 0
check_include_files.sh 0
check_tree_reader_tests.sh 0
check_complexity_ratchet.sh 0 PASS (D2) fe2fcb0 vs 93d8a38, pmat 3.44.0: none new, none grown
cargo llvm-cov -p aprender-viz --lib 0 stat_count.rs: 370 lines, 0 missed; 57 functions, 0 missed
pv validate n/a no contract changed

Mutants (in-diff: cargo mutants -p aprender-viz -f crates/aprender-viz/src/grammar/stat_count.rs)

rc 0. 81 tested: 68 caught, 0 missed, 0 timeout, 13 unviable. The 13 unviable mutants are all Default::default() replacements, and BarSpec, BarRow, DiscreteAxis and BuiltBars have no Default.

Known items

  • stat_count.rs keeps its own private DISCRETE_EXPAND_ADD (0.6), which duplicates scale_discrete::DISCRETE_EXPAND_ADD. It is kept so the code stays byte-identical to the source. Folding the two together is left to a later slice.

Not done

  • No workspace-wide nextest.
  • No review yet. This PR stays a draft and is not armed. Per the re-cut plan, Closes #6927 becomes Refs #6927 before ready unless this is the row-completing slice.

degraded: same-family

Closes #6927
Refs #6928
Refs #6938
Refs #6909
keep-open: #6909 is the master ticket; rows remain
ont-delta: none

🤖 Generated with Claude Code

Noah Gift and others added 7 commits November 13, 2026 15:37
First bars slice of the #6938 re-cut: BarRow, Position::{Identity, Stack,
Fill}, apply and apply_panels, ported from ggplot2 4.0.3 PositionStack /
PositionFill, plus unit tests whose expected values are ggplot_build()
output from R 4.6.2 + ggplot2 4.0.3.

Source: #6938 @ df9c227, crates/aprender-viz/src/grammar/position.rs.
Kept byte-identical: source lines 11-17, 31-50, 58-71, 78-112, 117-119,
126-127, 134-152, 159-226. Dropped (position_dodge, later slice): 18-30,
51-57, 72-77, 113-116, 128-133, 153-158, 227-267. New in slice: the
module doc (source 1-10), the apply_panels doc (source 120-125), the
mod.rs pub use without Preserve, and the tests module.

Refs #6909

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tests

Review of #7021 at e86f931 (non-author) found the module diverging from
ggplot2 4.0.3 on missing values, with tests that did not pin it:

- PositionStack$setup_data's detect_missing step: a row with NaN in any of
  x, xmin, xmax, y now has all four set to NaN (R's NA) and stacks as a
  zero-height bar; a NaN ymin/ymax edge comes out NaN (max_is_lower is NA).
  Previously a NaN y became a finite zero-height bar at the column top.
- has_repeated_x treats every NaN (either sign, any payload) as one value,
  as vctrs does, so x = (NaN, -NaN, 1) stacks.
- pmin/pmax propagate NaN, so a fill whose total overflows to Inf gives
  NaN like R instead of 0.
- apply() (re-exported as apply_position) now keeps the unique-x no-op
  that apply_panels had, so a negative bar over a unique x stays at y = -1.

Tests (expected values from R 4.6.2 + ggplot2 4.0.3, LC_ALL=C): N_nan_y
now checks all three rows; NaN / -NaN x; vjust = 2 on unique x (kills the
vjust >= 1.0 mutant); Inf/Inf fill; interleaved x (kills deleting the
xmin sort); crafted rows through PositionStack's own methods; the public
single-panel entry point.

Refs #6909

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…min NaN

Second non-author review of #7021 (at cf96750) found four surviving
mutants and one divergence on hand-built rows:

- pos_stack now implements max_is_lower: a row given with ymax < ymin
  keeps its stacked edges swapped (R: ymin 3, ymax 2 on P2). The old
  comment claimed this never happens for rows built by this crate, but
  BarRow is public and the crate builds none itself.
- Tests from R 4.6.2 + ggplot2 4.0.3 (PositionStack's own methods on
  hand-built rows): NaN xmin alone and NaN xmax alone blank the row
  (P10, P11); NaN ymin alone gives NA edges (P9); the swap (P2).
- Module doc: vjust = NaN errors in R only when no x repeats.

Refs #6909

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Third non-author review of #7021 (at c3d3576): a mutant that swaps
the edges only when ymax >= 0 survived all 24 position tests. R 4.6.2
+ ggplot2 4.0.3, running PositionStack's own methods on hand-built
rows y = (-1, -2), ymin = (0, 0), ymax = (-1, -2), gives y = (-2, 0),
ymin = (-2, 0), ymax = (-3, -2). This test pins that. No code change.

Refs #6909

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fourth non-author review of #7021 (at 86174f3) found eight surviving
mutants, each restricting the swap or the blanking to a sub-domain the
tests never reached. Cases from R 4.6.2 + ggplot2 4.0.3, PositionStack's
own methods on hand-built rows:

- T1: an Inf y is present; row 1 gets y = NaN with Inf edges.
- T4: vjust 0 keeps the negative-stack swap.
- T5b: a -0 ymax counts as 0.
- T12: position_fill(vjust = 0.5) keeps the swap.
- T13: a row alone in its column with ymin Inf, ymax -Inf is swapped.
- U1: a NaN-x row whose ymax is NaN gets NA edges.

No code change.

Refs #6909

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Second bars slice of the #6938 re-cut, stacked on B1 (position core).
stat_count.rs is #6938 @ df9c227 except lines 13-16 of the module
doc: the old note called the discrete-scales lane in flight and said
GGPlot::layout() calls bar_layout_in; neither is true at this slice.
Kept: BarSpec, BarStat, BarError, DiscreteAxis, BuiltBars, bar_layout,
bar_layout_in, stat_count, discrete_axis and the extents. mod.rs adds
the module and its pub use. Nothing in the grammar calls it yet.

New in this slice: the doc lines above and a unit-test module whose
expected values are ggplot_build() output from R 4.6.2 + ggplot2 4.0.3
(LC_COLLATE=C).

Refs #6909
Refs #6938

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@noahgift noahgift added this to the 0.74.2 milestone Nov 14, 2026
@paiml-fleet
paiml-fleet Bot marked this pull request as ready for review November 14, 2026 15:18
@github-actions

Copy link
Copy Markdown

§13.11 rung 1 — quorum shadow verdict

S13-SHADOW pr=7040 head=93d8a387990a28db0c8736f046eb1e5398752641 verdict=REFUSE class=Q1 arm_rc=1

Shadow mode: this records a verdict and merges nothing. A refusal
to arm is not a block (§13 adds zero rows to §7) — the pull request is
exactly as green as it was.

@noahgift

Copy link
Copy Markdown
Member Author

Non-author review: PASS at 93d8a38

Reviewer: gemini-4-hydrogen-high (agy lane, read-only, sandboxed; witness 2171c0dab31b3e8899fafc2ee809878b). Author model: Claude. Blocking findings: 0. Diff reviewed: feb1cac39...93d8a3879 (2 files, +598). No workflow, gate, threshold or allow-list edits. No unwrap()/expect() in production code; the 6 tests assert exact ggplot2 values and are not vacuous.

Non-blocking follow-ups (all in crates/aprender-viz/src/grammar/stat_count.rs):

  1. discrete_axis(&[], None) gives continuous_range = (0.4, 0.6) for empty levels, where scale_discrete::discrete_range(0, ..) gives (0.0, 1.0).
  2. bar_layout_in indexes x_pos[*i], group[*i], y[*i] unchecked: a caller passing a row index >= df.nrow() in panels panics (safe for facet::panels and 0..nrow).
  3. group_ids ranks (x, fill) in bytewise order, not x_levels order: matches the documented scope, diverges from add_group() if unsorted custom levels are ever passed.

Not measured by the reviewer: build, tests and clippy (CI measures them).

@noahgift
noahgift enabled auto-merge (squash) November 14, 2026 15:29
noahgift added a commit that referenced this pull request Nov 14, 2026
…s own files; cut-over tool; rollback without a train (#7001)

Non-author review of 1b4c25f (Sonnet lane), two blockers:

1. Cut-over deadlock. infra#4369 (b993c94cb) now opens train PRs as the
   App with a train-members: body. The residual aprender side: the
   round-1 train rule wanted one ont-delta line per member, so a train
   mixing a sweep member and a code-only member was red although each
   member alone is green. check_pr_ont_delta.sh train mode now judges
   each member exactly as alone: ci/sections.yml fetches pulls/N/files
   per member (--list-train-members / --member-files), a sweep member
   needs a valid first ont-delta line in its own `member #N` block, a
   missing member file list fails. 16 train rows, 6 mutants all killed.
   Spec: the planted App-opened train read-back is the merge condition;
   rollback without a train is a plain revert PR (its own merge ref
   carries the reverted ci.yml).
2. Stale greens. scripts/ci_train_cutover.sh: every open PR whose head
   does not contain the cut-over commit gets gh pr update-branch
   (--apply); the read-back (no --apply, exit 0) also flags a required
   green off a train ref. 19-row case table with a fake gh, 8 mutants
   all killed. Read-only live run found #7040 green on all three names
   under the old workflow.

Pmat-Ticket: #7001

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@noahgift
noahgift merged commit 3849aad into main Nov 14, 2026
31 checks passed
@noahgift
noahgift deleted the recut/b2-stat-count branch November 14, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLOT-GG-001 row: stat_count + geom_bar at ggplot2 4.0.3 oracle parity

1 participant