Skip to content

fix(analysis): Pivot Table says which cells it rounded past 2^53 - #1388

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
PawelKra:fix/pivot-table-rounded-notice
Nov 3, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
PawelKra:fix/pivot-table-rounded-notice

Conversation

@PawelKra

@PawelKra PawelKra commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pivot Table writes its statistics as decimals. A decimal holds whole numbers exactly only up to 2^53, so a SUM, MAX, FIRST, MEDIAN (and so on) of larger Integer values came out rounded with no notice. Summary Statistics, Dissolve and Summarize Within already check each result (stats::rounded) and report it through rounded_notice (#1253). Pivot Table called stats::compute directly and skipped the check.

Now Pivot Table checks each cell the same way and gives the same notices:

  • N results rounded in y2020, y2021: a decimal field holds whole numbers exactly only up to 2^53 (9007199254740992), counted per pivot field over every row;
  • N whole numbers written as text in v are past the 64-bit integer range and were read as decimals, … for a numeric value field holding such text, each record once.

Without a statistic, values are placed with the value field's type, exactly, and get no notice.

Before, with SUM of v, row field k and pivot field y on these records:

k y v
A 2020 9007199254740993
A 2020 2
A 2021 9007199254740993
B 2021 5

the A cells come out 9007199254740994 and 9007199254740992, with only:

Pivot Table: 2 rows, 2 pivot fields

After:

Pivot Table: 2 rows, 2 pivot fields
2 results rounded in y2020, y2021: a decimal field holds whole numbers exactly only up to 2^53 (9007199254740992)

Testing

  • cargo xtask ci.
  • New pivot_table_reports_rounded_cells in crates/analysis/tests/summary_fields.rs, on layers read by the real GeoJSON reader:
    • rounded SUM and MAX give the notice naming the pivot field;
    • statistics within 2^53, a MAX of exactly 2^53, COUNT and CONCATENATE give none;
    • cells are counted per pivot field across rows (3 results rounded in y2020, y2021);
    • placing values without a statistic keeps the Integer exactly and gives no notice;
    • a whole number written as text past the i64 range is reported once with a statistic and kept as it is without one.
  • Mutation check: dropping the per-cell count, counting into the wrong pivot field, dropping the text count, counting texts without a statistic, naming the wrong fields and dropping the notice each fail the test.

UI evidence

No visible UI change.

Related issue

Same kind of loss as the summary fields in #1253; no separate issue.

Summary by CodeRabbit

  • New Features
    • Pivot Table results now report when aggregated cells have been rounded due to precision limits, including counts by pivot field and affected whole-number text values.
  • Documentation
    • Clarified how Pivot Table statistics handle values beyond the whole-number precision limit.

Pivot Table writes its statistics as decimals, which hold whole numbers
exactly only up to 2^53, so a SUM, MAX, FIRST or MEDIAN of larger
Integer values came out rounded without a word. Summary Statistics,
Dissolve and Summarize Within already check each result and say how
many were rounded and in which fields.

Pivot Table now runs the same check on each cell and gives the same
notices: how many cells were rounded, naming the pivot fields that hold
them, and how many whole numbers written as text past the 64-bit range
a statistic read as decimals. Values placed without a statistic keep the
value field's type and get no notice.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Pivot Table now tracks precision loss in aggregated statistics. Its result includes notices that identify affected pivot fields and the number of rounded cells. Tests and user documentation cover these notices, including values written as text beyond the 64-bit integer range.

Changes: Pivot Table precision reporting

Layer / File(s) Summary
Track and report Pivot Table precision loss
crates/analysis/src/tools.rs, crates/analysis/tests/summary_fields.rs, docs/user-guide/analysis.md
Pivot Table counts rounded statistic cells by pivot field and includes precision-loss notices with its existing counts. The tests cover rounded and exact statistics, values placed without a statistic, and whole numbers written as text beyond the 64-bit integer range. The user guide describes the notices.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • opengeos/RustGIS#1253: Added shared rounding checks and text-value reporting that this change applies to Pivot Table.
  • opengeos/RustGIS#1084: Introduced Pivot Table aggregation and output behavior extended by this change.
  • opengeos/RustGIS#1070: Introduced shared statistics types and computation used by Pivot Table.

Suggested reviewers: deniial00

Merge Risk: Minimal · up to 4dafe

Pivot Table adds precision notices while preserving direct-placement behavior. No actionable merge-blocking risk was identified; merge after normal checks pass.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: Pivot Table now reports which cells it rounded past 2^53. The raw summary, PR objectives, and description all describe a per-cell rounding check and notice in Pivot Ta…
Description check Passed The description covers the summary of the change and why it is needed. It explains that Pivot Table called stats::compute directly and skipped the rounding check used elsewhere, and it gives example n…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Pivot Table now reports which cells it rounded past 2^53. The raw summary, PR objectives, and description all describe a per-cell rounding check and notice in Pivot Table, so the title matches the changeset. It is specific, concise, and uses the fix(analysis) convention.

Full details: Description check

Explanation

The description covers the summary of the change and why it is needed. It explains that Pivot Table called stats::compute directly and skipped the rounding check used elsewhere, and it gives example notices and a before/after table. The Testing section lists cargo xtask ci, the new test, and mutation checks. The UI evidence section keeps the required 'No visible UI change.' line. The Related issue section names #1253 as a related change, though it does not use the template's Closes or Part of wording. Those are minor gaps and do not affect the overall assessment.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (2 skipped: 1 unsupported, 1 too large.)

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each pivot cell,
And counts the rounded numbers well.
By field, the notice marks the sum,
While exact results stay quiet—mum.
Text too large gets counted, too;
The guide and tests explain what’s true.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b4bfc75b-8f0c-495f-9461-73bbc9684bf4
Commits

Reviewing files that changed from the base of the PR and between 417cd30 and 4dafe4e.

Files selected for processing: 3
  • crates/analysis/src/tools.rs
  • crates/analysis/tests/summary_fields.rs
  • docs/user-guide/analysis.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security problems or AGENTS.md violations in this PR. I checked the diff against stats::column, stats::rounded, Rounded::count_texts and rounded_notice, and traced the new test expectations by hand. I did not compile or run the tests, so that remains unverified.

Bugs: None found. The per-cell check uses the same stats::rounded as Summary Statistics, and the counts are indexed by pivot column with get_mut. The text count runs once over all records, so no record is counted twice. The notice wording matches the test strings.

Security: None found. The changed code has no indexing or unwraps in non-test code (get/get_mut/unwrap_or_default are used), and it adds no new input paths.

Performance: Nothing significant. With a statistic set, the change adds one extra O(n) column pass for the text count and one rounded check per cell. It does nothing when no statistic is given.

Quality (low confidence, optional):

  • With up to MAX_PIVOT_COLUMNS (1000) rounded pivot fields, the single "N results rounded in …" notice lists every field name. That can run to tens of kilobytes. A count, or a capped list, would be easier to read. This is a judgement call, so I did not post it inline.
  • docs/user-guide/analysis.md says Pivot Table "says how many cells were rounded and in which pivot fields". It doesn't mention the text-as-decimal notice, though "the same rules" covers it loosely.
  • In the new test, clean[0].to_string() is clunky next to the other literals. This is a release-quality-pass point, not a blocker.

AGENTS.md: Compliant. Notices go through ToolResult::messages with one notice per kind and a count. Both lossy and clean cases are tested. Pivot's previously silent rounding is now reported.

Prior reviews: None on this PR, so there were no earlier concerns to leave alone.

Inline comments: None posted, since I found nothing that needs a change.

Change size

Compared with the base branch: the whole PR against main (merge base 36f1807 to PR head 4dafe4e).

Files changed Added Modified Removed Renamed Size before Size after Total size change
3 0 3 0 0 686.9 KB 692.4 KB +5.5 KB
Path Size before Size after Size change
crates/analysis/tests/summary_fields.rs 50.0 KB 54.5 KB +4.5 KB
crates/analysis/src/tools.rs 545.0 KB 546.0 KB +970 B
docs/user-guide/analysis.md 91.8 KB 91.9 KB +94 B

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-1388/
Web app https://preview.rustgis.app/pr-1388/app/
Commit 4dafe4e

GitHub Pages takes a minute or two to publish a new commit.

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.

2 participants