Feature/choosecols function - #1734
Conversation
|
@Tobiadefami thanks for the pull request. No CLA step needed here — our records show you signed the Contributor License Agreement on 2026-07-31. That signature came from our previous signing form and has been carried over, so there is nothing for you to re-sign. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
hyperformula-docs | 58f0cbc | Commit Preview URL Branch Preview URL |
Sep 03 2026, 11:38 AM |
Performance comparison of head (58f0cbc) vs base (c920375) |
| * @param {ProcedureAst} ast - The parsed function-call AST node. | ||
| * @param {InterpreterState} state - The current interpreter evaluation state. | ||
| */ | ||
| public choosecolsArraySize(ast: ProcedureAst, state: InterpreterState): ArraySize { |
There was a problem hiding this comment.
Same finding as on #1722's TAKE: CHOOSECOLS(A:A,1) returns #VALUE! even on the same sheet, where real Excel spills correctly (confirmed live via MS Graph). SORT/UNIQUE/FILTER already support this in the same codebase — worth reusing whatever they do differently in array-size prediction rather than the current blanket rejection of non-finite dimensions.
known-limitations.md's new CHOOSECOLS entry is otherwise excellent, by the way — exactly the house style (HF's own behavior + consequence, no Excel-comparison framing). Once the same-sheet case is fixed, the "Spills the whole column when space is available" line in list-of-differences.md will need to become case-specific: same-sheet works, cross-sheet genuinely does not (confirmed #SPILL! in real Excel).
There was a problem hiding this comment.
Fixed in 0df4d1f; covered in test repo PR 34 by ed7a097. Direct Excel Online verification showed both same- and cross-sheet sources spill from row 1 and return #SPILL! below it, so the docs reflect that.
|
This PR also touches |
| } | ||
| } | ||
|
|
||
| return new ArraySize(ast.args.length - 1, effectiveHeight) |
There was a problem hiding this comment.
Finite height breaks column spills
High Severity
choosecolsArraySize now materializes whole-column results with a finite effectiveHeight snapshot instead of keeping an unbounded height. Array size is fixed when the formula is set, so when the source sheet later grows, evaluation returns more rows than predicted and ArrayValue.resize throws. SORT/UNIQUE/FILTER keep POSITIVE_INFINITY here so spill stays an AbsoluteColumnRange and can expand.
Reviewed by Cursor Bugbot for commit 0df4d1f. Configure here.
There was a problem hiding this comment.
I reran this against the current PR commit (0df4d1f28c) using both cross-sheet and same-sheet whole-column formulas.
One clarification: updating a source cell does reevaluate the formula, but it does not rerun the array-size predictor or rebuild the formula vertex.
Test setup
I started with three values in column A and then extended the sheet’s used height by adding a fourth value:
hf.setCellContents(
{ sheet: dataSheet, col: 0, row: 3 },
40,
)I tested the following cross-sheet formulas:
=CHOOSECOLS(Data!A:A, 1)
=SORT(Data!A:A)
=UNIQUE(Data!A:A)
I repeated the test using same-sheet references:
=CHOOSECOLS(A:A, 1)
=SORT(A:A)
=UNIQUE(A:A)
Result
All three functions throw the same error when the new value extends the used height of the source range:
Error: Resizing to smaller array
at ArrayValue.resize (.../src/ArrayValue.ts:141:13)
at ArrayFormulaVertex.setCellValue (.../src/DependencyGraph/FormulaVertex.ts:132:11)
at Evaluator.recomputeFormulaVertexValue (.../src/Evaluator.ts:141:21)
For the same-sheet tests, SORT and UNIQUE initially spill all three rows correctly. However, they still throw after adding the fourth source value.
The following control cases succeed:
- Updating a value within the source’s existing used height.
- Using a finite source such as
Data!A1:A4and then populatingA4.
Could you rerun the source-growth check against SORT and UNIQUE?
Based on these results, they do not currently expand successfully after the used height of a whole-column source increases.
It also appears that preserving Infinity during the initial array-size prediction is insufficient on its own. After the first evaluation, the array formula vertex holds the finite size of the materialized result. The subsequent, larger result then fails in ArrayValue.resize.
This may therefore require an engine-level change to spill allocation or predicted-size retention -- or another mechanism that allows an existing array formula vertex to grow during recalculation.
|
cursor review verbose=true |
|
Bugbot request id: serverGenReqId_13ccdf6c-fbd0-4e9c-ada9-f067011978d8 |
Bugbot rules debugBugbot rules included in this run
Bugbot request id: serverGenReqId_13ccdf6c-fbd0-4e9c-ada9-f067011978d8 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
There are 3 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0df4d1f. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1734 +/- ##
===========================================
+ Coverage 97.32% 97.36% +0.03%
===========================================
Files 195 195
Lines 15739 15817 +78
Branches 3390 3422 +32
===========================================
+ Hits 15318 15400 +82
+ Misses 421 417 -4
🚀 New features to boost your workflow:
|


Context
This PR adds
CHOOSECOLS, allowing columns to be selected from an array with positive or negative indexes while preserving the requested order and duplicate indexes.The implementation remains local to
ArrayPlugin;CHOOSEROWSis outside this PR's scope. It includes function metadata, translations, changelog and compatibility documentation.Behavior covered
#SPILL!below row 1.Validation
Companion tests: handsontable/hyperformula-tests#34
CHOOSECOLStests passed.git diff --checkpassed.#VALUE!even when the predicted spill range is blocked.Types of changes
Checklist
CHANGELOG.md.Note
Medium Risk
New dynamic-array spill logic touches array sizing and worksheet-edge behavior; mistakes could cause incorrect spills or error masking, but scope is isolated to ArrayPlugin with documented Excel-aligned edge cases.
Overview
Adds Excel-style
CHOOSECOLSso formulas can return selected columns from a range in a given order, including positive/negative indexing and repeated column numbers.The runtime and spill-size logic live in
ArrayPlugin: evaluation maps indexes to source columns (with bounds and empty-range handling), whilechoosecolsArraySizepredicts spill dimensions and statically validates literal column indexes viaparseChooseColsLiteralIndex. Whole-column sources may spill only from row 1; lower rows get#SPILL!, and documented limits cover scalar-only index arguments and spill-vs-error ordering when the spill range is blocked.Ships with lookup metadata, 16 localized function names, changelog entry, and compatibility/limitation docs (including a
CHOOSECOLSrow in the differences table vs Google Sheets on whole-column spill).Reviewed by Cursor Bugbot for commit 58f0cbc. Bugbot is set up for automated code reviews on this repo. Configure here.