Skip to content

Feature/choosecols function - #1734

Open
Tobiadefami wants to merge 4 commits into
developfrom
feature/choosecols-function
Open

Feature/choosecols function#1734
Tobiadefami wants to merge 4 commits into
developfrom
feature/choosecols-function

Conversation

@Tobiadefami

@Tobiadefami Tobiadefami commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Context

HyperFormula does not currently support CHOOSECOLS.

This change adds CHOOSECOLS, allowing columns to be selected from an array using positive or negative
indexes. It preserves the requested order and duplicate indexes and includes function metadata,
translations, documentation, and tests.

The implementation remains local to ArrayPlugin. CHOOSEROWS is outside the scope of this change.

How did you test your changes?

Added tests covering:

  • Required and repeated arguments.
  • Positive, negative, mixed, and duplicate indexes.
  • Fractional indexes and numeric coercion.
  • Cell-reference and calculated index arguments.
  • Scalar, range, whole-row, and calculated-array inputs.
  • Spill dimensions and blocked spill ranges.
  • Bounds validation and error propagation.
  • Reading only selected worksheet columns.
  • Public function metadata and localized function names.

All 35 focused tests passed.

The full Jest and browser test suites, TypeScript compilation, linting, and documentation generation also
completed successfully.

Types of changes

  • Breaking change (a fix or a feature because of which an existing functionality doesn't work as
    expected anymore)
  • 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:

None.

Checklist:

  • I have reviewed the guidelines about [Contributing to HyperFormula](https://
    hyperformula.handsontable.com/guide/contributing.html) and I confirm that my code follows the code style of
    this project.
  • I have signed the Contributor License Agreement.
  • My change is compliant with the [OpenDocument](https://docs.oasis-open.org/office/OpenDocument/v1.3/
    os/part4-formula/OpenDocument-v1.3-os-part4-formula.html) standard.
  • My change is compatible with Microsoft Excel.
  • My change is compatible with Google Sheets.
  • I described my changes in the [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/master/
    CHANGELOG.md) file.
  • My changes require a documentation update.
  • My changes require a migration guide.

Note

Medium Risk
New formula surface area in dynamic-array spill logic; bounded to ArrayPlugin but affects spill allocation and error reporting (#SPILL! vs runtime errors).

Overview
Adds the CHOOSECOLS dynamic-array function so formulas can return selected columns from a range in a given order (positive/negative indexes, duplicates allowed).

Implementation lives in ArrayPlugin: evaluation builds the result from range data or dependency-graph column slices, and choosecolsArraySize predicts spill dimensions. Literal column indexes are validated before spill allocation; whole-column sources only spill on the same sheet in row 0, otherwise #SPILL! applies.

Also ships function metadata, localized names across language packs, changelog entry, known-limitations notes (scalar index args only, spill behavior), and a list-of-differences row for whole-column spill vs Google Sheets.

Reviewed by Cursor Bugbot for commit f915ac4. Bugbot is set up for automated code reviews on this repo. Configure here.

@cla-external-contractor-signup

Copy link
Copy Markdown

@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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 2026

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 f915ac4 Commit Preview URL

Branch Preview URL
Aug 17 2026, 12:28 PM

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8e0ff87. Configure here.

Comment thread src/interpreter/plugin/ArrayPlugin.ts
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

Performance comparison of head (f915ac4) vs base (61ead73)

                                     testName |    base |    head | change
--------------------------------------------------------------------------
                                      Sheet A |  518.59 |  503.77 | -2.86%
                                      Sheet B |  170.98 |  164.64 | -3.71%
                                      Sheet T |  144.74 |  141.87 | -1.98%
                                Column ranges |  534.85 |  529.87 | -0.93%
                                Sorted lookup | 15435.6 | 15009.1 | -2.76%
Sheet A:  change value, add/remove row/column |   18.32 |    17.8 | -2.84%
 Sheet B: change value, add/remove row/column |  162.36 |  148.71 | -8.41%
                   Column ranges - add column |  177.26 |  170.38 | -3.88%
                Column ranges - without batch |  556.01 |  505.74 | -9.04%
                        Column ranges - batch |  141.66 |   129.4 | -8.65%

* @param {Ast} argument - The column-index argument to inspect without evaluating formulas.
* @returns {ChooseColsLiteralIndex} A coerced literal value, an invalid marker, or an unresolved marker.
*/
private parseChooseColsLiteralIndex(argument: Ast): ChooseColsLiteralIndex {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codecov/patch is red because of exactly two untested lines: the PLUS_UNARY_OP branch (e.g. =CHOOSECOLS(A1:D3,+2)) and the PARENTHESIS branch (e.g. (2)). One or two literal-index tests for these should close it completely.

* @param {ProcedureAst} ast - The parsed function-call AST node.
* @param {InterpreterState} state - The current interpreter evaluation state.
*/
public choosecolsArraySize(ast: ProcedureAst, state: InterpreterState): ArraySize {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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).

@marcin-kordas-hoc

Copy link
Copy Markdown
Collaborator

This PR also touches script/release/release.sh (adds a release-checklist line: "Review the deployed docs and test the demos"), which is unrelated to CHOOSECOLS and not mentioned in the description — it says the change is "local to ArrayPlugin." Either split it out into its own PR, or explain why it is bundled here.

@Tobiadefami
Tobiadefami changed the base branch from master to develop August 17, 2026 10:27
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.34%. Comparing base (61ead73) to head (f915ac4).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1734      +/-   ##
===========================================
+ Coverage    97.31%   97.34%   +0.03%     
===========================================
  Files          195      195              
  Lines        15719    15789      +70     
  Branches      3455     3413      -42     
===========================================
+ Hits         15297    15370      +73     
- Misses         414      419       +5     
+ Partials         8        0       -8     
Files with missing lines Coverage Δ
src/i18n/languages/csCZ.ts 100.00% <ø> (ø)
src/i18n/languages/daDK.ts 100.00% <ø> (ø)
src/i18n/languages/deDE.ts 100.00% <ø> (ø)
src/i18n/languages/enGB.ts 100.00% <ø> (ø)
src/i18n/languages/esES.ts 100.00% <ø> (ø)
src/i18n/languages/fiFI.ts 100.00% <ø> (ø)
src/i18n/languages/frFR.ts 100.00% <ø> (ø)
src/i18n/languages/huHU.ts 100.00% <ø> (ø)
src/i18n/languages/idID.ts 100.00% <ø> (ø)
src/i18n/languages/itIT.ts 100.00% <ø> (ø)
... and 9 more

... and 6 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.

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