Skip to content

Fix whole-column and whole-row references to an empty sheet (HF-604) - #1908

Open
Tobiadefami wants to merge 2 commits into
developfrom
fix/hf-604-empty-sheet-whole-column
Open

Tobiadefami wants to merge 2 commits into
developfrom
fix/hf-604-empty-sheet-whole-column

Conversation

@Tobiadefami

@Tobiadefami Tobiadefami commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Context

A whole-column or whole-row reference to a sheet with no cells, such as =VSTACK(Data!A:A), throws an exception in VSTACK, TRANSPOSE and other array functions, and in LEN and operators with array arithmetic on. TAKE, SORT, UNIQUE and similar functions return an error instead. The reference is sized by the sheet's height, which is 0, and an array can't be empty. #1346 made empty ranges safe for SUM and MATCH, but not for code that builds an array from them.

Now such a column or row reads as one blank cell, as on a sheet with one row or column. AbsoluteColumnRange and AbsoluteRowRange keep two things apart:

  • the value's size (effectiveHeight, effectiveWidth) is at least 1;
  • the cells the range depends on (effectiveEndRow, effectiveEndColumn) stop at the sheet's last row or column, so on an empty sheet there are none.

No cell is created, getSheetDimensions() still returns 0×0, and a value entered later is picked up. The empty-source checks in CHOOSECOLS, CHOOSEROWS, TAKE, EXPAND, WRAPROWS, WRAPCOLS and SORT can no longer fire, so I removed them and the docs lines about them.

I rejected two alternatives:

  • Raising the sheet height to 1 everywhere creates a cell on the empty sheet and changes getSheetDimensions(), INDEX, MEDIAN, COUNTIF and ISBLANK.
  • A check in each array function misses the operator, LEN and IF crashes, and every new function would need it too.

How did you test your changes?

  • npx jest in hyperformula/ with the paired branch fix/hf-604-empty-sheet-whole-column (handsontable/hyperformula-tests#127): 14,903 passed, 3 skipped.
  • In the 12 changed spec files, 29 tests fail on develop and pass here.
  • 79 formulas that read a whole column or row (array functions, aggregates, lookups, operators, IF, ISBLANK, LEN), run on develop and here, with array arithmetic off and on, against an empty sheet and four sheets with cells: only the empty-sheet results change, and none throws.
  • npm run lint and npm run verify:typings pass.

AI assistance

Claude Code wrote the change, docs and tests, compared the alternatives and ran the Excel checks.

Compatibility with Excel and Google Sheets

With the Data sheet empty. Google Sheets not checked.

Formula Microsoft Excel Online HyperFormula before HyperFormula now
=VSTACK(Data!A:A) 0 in 1,048,576 rows Throws One blank cell
=TAKE(Data!A:A, 1) 0 #N/A Blank cell
=UNIQUE(Data!A:A) 0 #CALC! Blank cell
=SUM(CHOOSECOLS(Data!A:A, 1)) 0 #N/A 0
=MMULT(TRANSPOSE(Data!A:A), Data!A:A) #VALUE! 0 #VALUE!
=COUNTBLANK(Data!A:A) 1048576 #N/A 1
=COUNTIF(Data!A:A, "") 1048576 0 1
=AND(Data!A:A) #VALUE! #N/A FALSE
=MEDIAN(Data!A:A) #NUM! #NUM! 0
=INDEX(Data!A:A, 2) 0 0 #REF!

Every "now" value is what develop already returns on a sheet with one blank row.

Public API changes

None.

Out of scope and follow-ups

  • MEDIAN and INDEX move away from Excel because HyperFormula reads a one-cell range as a single value. Changing that also changes results on sheets with cells.
  • COUNTBLANK and COUNTIF count a whole column's used rows, not all 1,048,576, on any sheet.

Types of changes

  • Breaking change (existing functionality no longer works as before) – agreed with the maintainers
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues

  1. HF-604
  2. Tests: handsontable/hyperformula-tests#127

Checklist

🤖 Generated with Claude Code

Tobiadefami and others added 2 commits November 23, 2026 14:48
A whole-column or whole-row reference to a sheet with no cells threw an
exception in array functions, LEN and operators, or returned an error in
TAKE, SORT, UNIQUE and similar functions, because its value was sized by
the sheet's height of 0.

AbsoluteColumnRange and AbsoluteRowRange now keep the value's size
(at least 1) apart from the cells the range depends on (none on an empty
sheet), so such a column or row reads as one blank cell, as on a sheet
with one row or column, without creating a cell. The empty-source checks
that can no longer fire are removed.

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

@handsontable-pr-review handsontable-pr-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Medium risk: The change touches core range-sizing semantics (effectiveHeight/effectiveWidth and range materialization via addressesArrayMap) on the main calculation path, but I verified the new limits coincide exactly with the old ones for every bounded range and for whole-column/row ranges on non-empty sheets, so the behavioural blast radius is confined to whole-column/row references on empty sheets plus the

Full review: no issues found.

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Performance comparison of head (70f5ec4) vs base (462cf9b)

                                     testName |    base |    head | change
--------------------------------------------------------------------------
                                      Sheet A |  508.13 |  522.09 | +2.75%
                                      Sheet B |  168.45 |  173.89 | +3.23%
                                      Sheet T |  147.91 |  153.88 | +4.04%
                                Column ranges |  484.52 |  490.58 | +1.25%
                                Sorted lookup | 15587.1 | 14968.9 | -3.97%
Sheet A:  change value, add/remove row/column |    17.1 |   18.11 | +5.91%
 Sheet B: change value, add/remove row/column |  143.02 |  153.25 | +7.15%
                   Column ranges - add column |  162.84 |  166.97 | +2.54%
                Column ranges - without batch |  477.21 |  498.35 | +4.43%
                        Column ranges - batch |  115.14 |  122.78 | +6.64%

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
hyperformula-docs 70f5ec4 Commit Preview URL

Branch Preview URL
Nov 23 2026, 01:53 PM

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.63%. Comparing base (576d838) to head (70f5ec4).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1908      +/-   ##
===========================================
- Coverage    97.64%   97.63%   -0.01%     
===========================================
  Files          212      212              
  Lines        18328    18322       -6     
  Branches      4258     4287      +29     
===========================================
- Hits         17896    17889       -7     
- Misses         424      433       +9     
+ Partials         8        0       -8     
Files with missing lines Coverage Δ
hyperformula/src/AbsoluteCellRange.ts 95.30% <100.00%> (+0.03%) ⬆️
hyperformula/src/interpreter/plugin/ArrayPlugin.ts 99.08% <100.00%> (-0.31%) ⬇️
hyperformula/src/interpreter/plugin/SortPlugin.ts 100.00% <ø> (ø)

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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