Skip to content

fix(table-core): skip NaN in min, max and extent aggregations - #6674

Open
HEOJUNFO wants to merge 1 commit into
TanStack:mainfrom
HEOJUNFO:feat-range-aggregation-nan
Open

HEOJUNFO wants to merge 1 commit into
TanStack:mainfrom
HEOJUNFO:feat-range-aggregation-nan

Conversation

@HEOJUNFO

@HEOJUNFO HEOJUNFO commented Nov 25, 2026 •

Copy link
Copy Markdown

🎯 Changes

min, max and extent return NaN when the first value of a group is NaN, and ignore the same NaN anywhere else in the group. So the aggregate of one set of values depends on row order:

// column: { accessorKey: 'amount', aggregationFn: ['min', 'max', 'extent'] }
table.getColumn('amount').getAggregationValue()

// amounts [NaN, 3, 1] -> { min: NaN, max: NaN, extent: [NaN, NaN] }
// amounts [3, NaN, 1] -> { min: 1,   max: 3,   extent: [1, 3] }

(Run on main with constructTable and the rowAggregationFeature + aggregationFns test fixture.)

The first valid value seeds the running result, and getRangeKind counts NaN as a valid number. Every later valueNumber - resultNumber < 0 is then false, so the seed is never replaced. A leading NaN also fixes the group's kind to 'number', so a group of Dates behind it is dropped. The merge paths go through the same helper.

v8 skipped NaN in all three (min === undefined && value >= value); with the v8 functions both orders above give 1, 3, [1, 3]. This change makes getRangeKind return undefined for NaN, which restores that for aggregate and merge. The JSDoc of min/max said NaN "preserves the legacy numeric seeding behavior", so I reworded it to say it is ignored. sum is untouched (it still propagates NaN, as its test expects).

Not included: median also gives order-dependent results with NaN (its sort comparator returns NaN), but v8 did the same and #6655 is open on that function. The generated docs/reference pages for min/max still carry the old sentence; I left them for the next docs regeneration.

Checks run in packages/table-core:

  • npx vitest run tests/unit/fns/aggregationFns.test.ts — the new test fails on main (expected NaN to be 1), 9/9 pass with the fix
  • npx vitest run tests/unit/fns/aggregationFns.test.ts tests/implementation/features/row-aggregation/rowAggregationFeature.test.ts tests/implementation/features/column-grouping tests/unit/features/column-grouping tests/unit/worker/serializeRebuild.test.ts — 80 passed
  • npx eslint and npx prettier --check on the changed files, npx tsc — clean

I did not run the full pnpm test / pnpm test:e2e.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm test and pnpm test:e2e, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Minimum, maximum, and range aggregations now ignore NaN values, including when combining results. Groups with a NaN first value can now produce valid results from other values.

A NaN in the first row of a group became the running result and was never
replaced, because every later comparison against it is false. The same
values in another row order aggregated normally. v8 skipped NaN in these
three aggregations (its `value >= value` guard).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 721ca40

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@tanstack/table-core Patch
@tanstack/alpine-table Patch
@tanstack/angular-table-devtools Patch
@tanstack/angular-table Patch
@tanstack/ember-table Patch
@tanstack/lit-table Patch
@tanstack/octane-table Patch
@tanstack/preact-table Patch
@tanstack/react-table Patch
@tanstack/solid-table Patch
@tanstack/svelte-table Patch
@tanstack/vue-table Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The min, max, and extent aggregations now skip numeric NaN values. Tests cover aggregation and merge inputs, including all-NaN values and dates after a leading NaN.

Changes: Range Aggregations

Layer / File(s) Summary
NaN handling and validation
packages/table-core/src/features/row-aggregation/aggregationFns.ts, packages/table-core/tests/unit/fns/aggregationFns.test.ts, .changeset/skip-nan-range-aggregations.md
The range-kind check rejects numeric NaN values. Tests cover aggregation and merge behavior. The changeset and min/max documentation state that NaN is ignored.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: kevinvandy

Merge Risk: Minimal · up to 721ca

This change makes min, max and extent skip NaN values so results no longer depend on row order. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: min, max and extent aggregations now skip NaN. It follows the conventional commit format and matches the raw summary, the description, and the PR objectives. The title…
Description check Passed The description follows the template. The Changes section explains the bug, the reproduction, the root cause in getRangeKind, the v8 behavior, and the JSDoc update. It also lists the test runs and sta…
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: min, max and extent aggregations now skip NaN. It follows the conventional commit format and matches the raw summary, the description, and the PR objectives. The title is specific and concise.

Full details: Description check

Explanation

The description follows the template. The Changes section explains the bug, the reproduction, the root cause in getRangeKind, the v8 behavior, and the JSDoc update. It also lists the test runs and states what was not run. The checklist is marked, and the Release Impact section has the changeset box checked. The two unchecked template items (the pnpm test checkbox and the docs/CI-only checkbox) are not required by the author's stated scope, so the description is mostly complete.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6d48b56 and 721ca40.

Files selected for processing: 3

  • .changeset/skip-nan-range-aggregations.md
  • packages/table-core/src/features/row-aggregation/aggregationFns.ts
  • packages/table-core/tests/unit/fns/aggregationFns.test.ts

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

This branch has not been deployed

No deployments
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.

1 participant