Repository navigation
Add DROP function (HF-384) - #1796
Conversation
TAKE shipped with the English name in 10 of 16 packs while 6 carried a
translation, and VSTACK/HSTACK were English in all 16. Microsoft localizes
all three in most locales, so a user could not type the name their Excel
uses.
Names taken from Microsoft's localized "Excel functions (alphabetical)"
page, one locale at a time. Each row there links to the function's own page
using the English slug in the href while the link text is the localized
name, so the lookup is exact:
<a href="functions/take-function">WYCINEK</a>
Left as English where Microsoft itself does not translate: TAKE, VSTACK and
HSTACK in Indonesian, and VSTACK/HSTACK in Swedish.
Note that a function's own localized page is not a usable source: for
several locales its syntax block still shows the English name even though
the prose and argument names are translated (the French page shows
"=TAKE(tableau, lignes,[colonnes])" while the product uses PRENDRE).
DEV_DOCS records the lookup method and adds the governing policy: ship a
localized name only when it can be confirmed against the product, and keep
the English name otherwise, since an invented name matches nothing, reads
plausibly enough to be typed first, and fails as #NAME?.
No changelog entry: TAKE, VSTACK and HSTACK are all still in [Unreleased],
so no wrong name has been released.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This reverts commit 4459034.
### Context An array formula whose result is a whole column or a whole row, such as `=SORT(Data!A:A)` or `=FILTER(Data!A:A, Data!A:A>0)`, only fits at the matching sheet edge. Placed anywhere else, it has no room to spill. Before this PR, the error depended on how the formula reached the cell: | How the formula is entered | Result | |---|---| | `buildFromSheets` / `buildFromArray` | `#SPILL!` "No space for array result." | | `setCellContents` | `#ERROR!` "Parsing error. Invalid range size." | The second result is misleading: the formula parses fine. Cause: `DependencyGraph.exchangeOrAddFormulaVertex` builds the result area with `AbsoluteCellRange.spanFrom`, which throws when an unbounded area can't be placed. The catch in `Operations.setCellContent` (added in #1311 to stop the runtime exception from #1267) stores that throw as a parsing error. The build path uses `spanFromOrUndef` in `setAddressMappingForArrayVertex` and reaches the normal space check, which returns `#SPILL!`. This PR makes `exchangeOrAddFormulaVertex` use `spanFromOrUndef` and skip the result-area mapping when the area can't be placed, like the build path. It also marks the vertex as no-space (`setNoSpace`) right away. That puts it in the state the build path reaches after evaluation: a one-cell `#SPILL!` array. Without that step, clearing or overwriting the cell while evaluation is suspended (`suspendEvaluation` or `batch`) would call `getRange` on the unbounded vertex and crash. The formula is stored and evaluates to `#SPILL!`. Arrays that can be placed, and non-array formulas, are unchanged. `#SPILL!` is also what Excel shows for a whole-column result that can't fit (measured in Excel Online for `TAKE` and `DROP` whole-column results placed below the first row). #1311 changed a runtime exception into a cell error, and that still holds. Only the error changes, to the `#SPILL!` the build path already returns. ### How did you test your changes? - Tests: handsontable/hyperformula-tests#73. - The two `setCellContents` tests in `ranges.spec.ts` that expected `#ERROR!` "Invalid range size" for `=A:A+B1` and `=A:A+1:1` now expect `#SPILL!`, matching the build-path tests next to them. - New tests for FILTER and SORT over a whole column entered below the first row: - the result is `#SPILL!`, and the formula is stored; - no cells below are reserved; - undo restores the previous value, and redo returns `#SPILL!`; - clearing it while evaluation is suspended, and overwriting it inside a `batch`, both work; - it is `#SPILL!` after evaluation resumes, and stays `#SPILL!` when its source changes; - control: the same function over a bounded range still spills normally. - On `develop`, 7 of those tests fail: every test that expects `#SPILL!`. With this PR, all 19 tests in `ranges.spec.ts` pass. With only the first commit (no `setNoSpace`), the suspended-clear and `batch` tests crash. That is the case Cursor Bugbot reported on this PR. - An additional script compared engines built both ways through the same 9 steps (initial, edit another cell, insert rows, remove rows, undo, redo, move the formula to A1, clear, undo the clear) for FILTER and SORT over a whole column. It also covered `DROP` and `TAKE` whole-column results, run on the #1796 branch. With this fix, the two paths returned identical results at all 54 steps. Before it, every step that left the formula below the first row differed. - Full Jest suite: 502/502 suites, 6,244 tests passed, 3 skipped. `tsc --noEmit` passes, and lint reports no new warnings in `DependencyGraph.ts`. ### 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) - [x] 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. Follow-up to #1311 / #1267. 2. Found while reviewing #1796, which adds `DROP`. `DROP` and `TAKE` (#1722) go through the same path. 3. Tests: handsontable/hyperformula-tests#73 ### Checklist: - [x] I have reviewed the guidelines about [Contributing to HyperFormula](https://hyperformula.handsontable.com/docs/guide/contributing.html) and I confirm that my code follows the code style of this project. - [x] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [ ] 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. - [x] My change is compatible with Microsoft Excel. - [ ] My change is compatible with Google Sheets. - [x] 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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches array-formula graph setup on every `setCellContents` edit; behavior change for callers that relied on the old `#ERROR!` message, but bounded arrays and non-array formulas are unchanged. > > **Overview** > **`setCellContents`** now reports **`#SPILL!`** (not **`#ERROR!` / "Invalid range size"**) when an array formula’s whole-column or whole-row result cannot fit at the entry cell—e.g. **`=SORT(A:A)`** below row 1—matching **`buildFromSheets`** and Excel. > > In **`DependencyGraph.exchangeOrAddFormulaVertex`**, the spill area is computed with **`spanFromOrUndef`** instead of **`spanFrom`**, so an unplaceable unbounded result no longer throws and gets misclassified as a parse error. When no range can be placed, array vertices are marked **`setNoSpace()`** immediately and spill mapping is skipped, avoiding crashes when clearing or overwriting the cell during **`suspendEvaluation`** or **`batch`**. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5b19c60. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Below the first row, TAKE returned #SPILL! for any count read from a cell when the whole-column or whole-row source was on the formula's own sheet, because a larger result used to throw. A result taller or wider than its reserved area now returns #SPILL! on its own, so the guard is no longer needed: counts that fit spill, as in Excel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ure/hf-384-drop # Conflicts: # hyperformula/src/interpreter/plugin/ArrayPlugin.ts
An empty rows argument still keeps every row, as in Microsoft Excel; it is now detected in the method instead of through a default value, which made getFunctionDetails report the argument as optional. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md # docs/guide/list-of-differences.md # hyperformula/src/interpreter/plugin/ArrayPlugin.ts # hyperformula/src/license/functionCapabilities.ts
…feature/hf-384-drop # Conflicts: # hyperformula/src/interpreter/plugin/ArrayPlugin.ts # hyperformula/src/license/functionCapabilities.ts
There was a problem hiding this comment.
Note
Medium risk: Adds the DROP function to the calculation engine (shared helpers with TAKE, spill-size prediction, i18n dictionaries); this part covers docs, 17 locale dictionaries and function metadata, while the runtime implementation is in the second file set, so breakage is limited to the new function and the TAKE helper refactor.
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).
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
Both threads check out at ac175c1: =DROP(A:A,B1) in row 5 of the source's sheet and the cross-sheet layout in row 3 return #SPILL!, as in Excel Online, and the list of differences now has the =SUM(DROP(A:A, -1)) row, 10 here and 15 in Excel. Putting the old placement condition back fails 3 of the 81 tests. The branch merges develop without conflicts, and unit-tests passed at this head.
blocking: the description is still on the old template, without the AI assistance section that the Definition of Done asks for when an AI tool wrote the change; the DROP commits are co-authored by Claude. The current template also has the Compatibility with Excel and Google Sheets, Public API changes and Out of scope sections.
suggestion: two other parts of the description are out of date: #1722 is merged, so the stacking note can go, and the list of differences gets eight rows, not four.
|
The description now uses the current template, with the AI assistance, Compatibility with Excel and Google Sheets, Public API changes and Out of scope sections. The stacking note is gone, and the description counts eight list-of-differences rows. The branch merges |
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
At 781a2ab with hyperformula-tests at 9239369b0e, the description is on the current template with the AI assistance section, the stacking note is gone, and it counts the eight list-of-differences rows the diff adds. The 82 DROP tests pass, and putting the old placement condition back still fails 3. Since my last review the engine branch has only merged develop.
### Context Microsoft Excel returns `#CALC!` when a function cannot calculate its result, most often when the result would be an empty array. HyperFormula had no such error and returned `#N/A` or `#VALUE!` in those cases. This adds `ErrorType.CALC` and switches the functions where Excel returns it: | Function | Case | Before | After | |---|---|---|---| | `FILTER` | No value meets the conditions | `#N/A` | `#CALC!` | | `UNIQUE` | Nothing is kept (`exactly_once` is `TRUE` and every row or column repeats) | `#N/A` | `#CALC!` | | `SEQUENCE` | Rows or columns truncate to 0 (`0`, `0.5`, `FALSE()`, a blank cell) | `#VALUE!` | `#CALC!` | | `CONCAT`, `TEXTJOIN` | The result is longer than 32,767 characters | `#VALUE!` | `#CALC!` | This is a breaking change, so it targets 4.0.0: - `TranslationPackage` validates error keys exhaustively, so a custom language pack without `errors.CALC` makes `registerLanguage()` throw a `MissingTranslationError`. - `IFNA()` and `ISNA()` no longer catch the errors listed above. `ERROR.TYPE` returns `14` for `#CALC!`, the number Excel uses. Each built-in language pack gets the name Excel uses in that language, for example `#OBL!` (Polish), `#HESAPLA!` (Turkish), `#KALK!` (Swedish); German, French, Dutch and several others keep `#CALC!`. The names were checked in Microsoft Excel Online set to each language. Microsoft's localized "How to correct a #CALC! error" pages are not reliable for this (the Finnish, Portuguese and Russian pages say `#CALC!` where Excel shows `#LASKE!`, `#CÁLC!` and `#ВЫЧИСЛ!`, and the Danish and Dutch pages give names Excel doesn't use), so `dev-docs/I18N.md` now says to confirm every error name in Excel. The `hyperformula-ui` formula lexer now recognises `#CALC!`, so the editor no longer marks it as invalid. `SORT` keeps `#N/A` for an empty input. Excel never returns `#CALC!` there: `SORT` of an empty column returns blank rows. HyperFormula's branch only guards a zero-width sheet. `SEQUENCE` now checks for a row count above `maxRows` before checking for a dimension of 0, and for a column count above `maxColumns` after it. This is the order Excel follows: `=SEQUENCE(2000000,0)` is `#VALUE!`, `=SEQUENCE(0,20000)` is `#CALC!`. ### How did you test your changes? - `npx jest` in `hyperformula/` with the paired `hyperformula-tests` branch `feat/hf-134-calc-error` (handsontable/hyperformula-tests#118): 539 suites, 8,379 tests passed. - `npx tsc --noEmit`, and `eslint` on the changed files: no errors. - `npm run docs:build`: passes, including the new migration guide. ### AI assistance Claude Code wrote parts of the code, tests and docs, and ran the Excel comparison. ### Compatibility with Excel and Google Sheets Checked in Microsoft Excel Online: | Formula | Excel | Google Sheets | HyperFormula | |---|---|---|---| | `=FILTER({1;2;3},{1;2;3}>5)` | `#CALC!` | Not checked | `#CALC!` | | `=UNIQUE({1;1;2;2},,TRUE())` | `#CALC!` | Not checked | `#CALC!` | | `=SEQUENCE(0)`, `=SEQUENCE(0.5)`, `=SEQUENCE(1,0)` | `#CALC!` | Not checked | `#CALC!` | | `=SEQUENCE(-1)`, `=SEQUENCE(0,-1)` | `#VALUE!` | Not checked | `#VALUE!` | | `=SEQUENCE(2000000,0)` | `#VALUE!` | Not checked | `#VALUE!` | | `=CONCAT(REPT("a",32767),"b")` | `#CALC!` | Not checked | `#CALC!` | | `=TEXTJOIN("",FALSE(),REPT("a",32767),"b")` | `#CALC!` | Not checked | `#CALC!` | | `=IFNA(FILTER({1},{0}),"x")` | `#CALC!` | Not checked | `#CALC!` | | `=ISERR(FILTER({1},{0}))` | `TRUE` | Not checked | `TRUE` | | `=ERROR.TYPE(FILTER({1},{0}))` | `14` | Not checked | `14` | | `=SORT(A:A)` on an empty column | blank rows | Not checked | blank | Added to `list-of-differences.md`: empty text used as a number (`=""+1`, `=ABS("")`, `=SEQUENCE("")`) is `#VALUE!` in Excel. HyperFormula reads it as `0`, so `=SEQUENCE("")` now returns `#CALC!`. ### Public API changes - `ErrorType.CALC` added. - `RawTranslationPackage.errors` must include `CALC`. ### Out of scope and follow-ups - `TAKE` (#1722), `DROP` (#1796), `TOROW`/`TOCOL` (#1828), and `WRAPROWS`/`WRAPCOLS`/`EXPAND` (#1830) return `#N/A` for an empty result while they wait for this error type. Whichever of those PRs and this one merges second switches them to `#CALC!`. ### Types of changes - [x] 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) - [x] Additional language file, or a change to an existing language file (translations) - [x] Change to the documentation ### Related issues 1. Fixes #1647 (HF-134) ### Checklist - [x] My pull request meets the [Definition of Done](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DEFINITION-OF-DONE.md). External contributors: see also [Contributing to HyperFormula](https://handsontable.com/docs/hyperformula/guide/contributing.html). - [ ] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [x] I read my own diff end to end before requesting a review. - [x] I added a [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/develop/CHANGELOG.md) entry, written by [the changelog rules](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DOC-STANDARDS.md#the-changelog) – or none is needed (docs, tests or tooling only). - [x] I updated the documentation and JSDoc to match the change. - [x] Breaking change only: I added a section to the migration guide. - [x] I updated the `dev-docs/` pages this change affects – or none needed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **High Risk** > Breaking error semantics across array and text functions and mandatory i18n keys will change formula results and can break custom language packs and error-handling logic on upgrade. > > **Overview** > Adds **`ErrorType.CALC`** (`#CALC!`) as a breaking 4.0 change so HyperFormula matches Excel when a function cannot produce a result—especially empty arrays or oversized text. > > **`FILTER`**, **`UNIQUE`** (empty result), **`SEQUENCE`** (truncated row/column count of 0), and **`CONCAT`** / **`TEXTJOIN`** (over 32,767 characters) now return **`#CALC!`** instead of **`#N/A`** or **`#VALUE!`**. **`IFNA()`** and **`ISNA()`** no longer handle these cases; callers need **`IFERROR()`** / **`ISERROR()`** or explicit **`ErrorType.CALC`** checks. **`SEQUENCE`** also reorders validation so oversized row counts are checked before zero-dimension **`#CALC!`**, like Excel. > > All built-in language packs gain localized **`errors.CALC`** strings; **`registerLanguage()`** throws **`MissingTranslationError`** if a custom pack omits **`CALC`**. Docs include a **3.x → 4.0** migration guide, updated error/compatibility pages, and changelog entry. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3166a31. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md # hyperformula/src/i18n/languages/csCZ.ts # hyperformula/src/i18n/languages/daDK.ts # hyperformula/src/i18n/languages/deDE.ts # hyperformula/src/i18n/languages/enGB.ts # hyperformula/src/i18n/languages/esES.ts # hyperformula/src/i18n/languages/fiFI.ts # hyperformula/src/i18n/languages/frFR.ts # hyperformula/src/i18n/languages/huHU.ts # hyperformula/src/i18n/languages/idID.ts # hyperformula/src/i18n/languages/itIT.ts # hyperformula/src/i18n/languages/nbNO.ts # hyperformula/src/i18n/languages/nlNL.ts # hyperformula/src/i18n/languages/plPL.ts # hyperformula/src/i18n/languages/ptPT.ts # hyperformula/src/i18n/languages/ruRU.ts # hyperformula/src/i18n/languages/svSE.ts # hyperformula/src/i18n/languages/trTR.ts # hyperformula/src/license/functionCapabilities.ts
# Conflicts: # CHANGELOG.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1796 +/- ##
========================================
Coverage 97.59% 97.59%
========================================
Files 212 212
Lines 18030 18070 +40
Branches 4141 4151 +10
========================================
+ Hits 17596 17636 +40
Misses 426 426
Partials 8 8
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Warning
High risk: The PR adds a new built-in dynamic-array function and a new #CALC! error type that touch the evaluator, spill prediction and the parser's name/error resolution for all 15 locales, plus a refactor of the existing TAKE code paths.
Incremental review: 2 potential issue(s).
hyperformula/src/i18n/languages/trTR.ts:278
VALUE renamed in trTR breaks existing =DEĞER() formulas
Medium severity
VALUE's Turkish name changes from 'DEĞER' to 'SAYIYAÇEVİR' and 'DEĞER' is reassigned to PRICE (line 214). Any stored formula in the trTR locale using =DEĞER(...) stops resolving to VALUE after the upgrade — it now maps to PRICE (a different function) or fails to parse, silently changing results. Renaming a long-shipped function's localized alias is a data-compatibility break for existing workbooks, and it is bundled unannounced into a PR whose description covers only DROP.
Suggestion: Keep 'DEĞER' as VALUE (or register it as a compatibility alias) and put the locale realignment in its own, documented change.
docs/guide/list-of-differences.md:136
New #CALC! error contradicts PR's own DROP documentation
Medium severity
This diff introduces a #CALC! error into HyperFormula (CALC translations added to the errors table of all 15 locale files, e.g. enGB.ts L10) and changes the documented result of =SEQUENCE(0) from #VALUE! to #CALC! (L136), while the same PR's DROP rows (L151-L152) and its description still state that HyperFormula "does not have" #CALC! and returns #N/A for an empty DROP result. Either the engine now emits #CALC! (making the SEQUENCE/CONCAT behavior change an undocumented breaking change for callers matching on #VALUE!, and making the DROP rows' rationale stale), or it does not (making L136 and the CALC locale entries wrong). One of the two halves of this changeset is necessarily incorrect as shipped.
Suggestion: Reconcile the DROP rows, the SEQUENCE row and the CALC error additions: if #CALC! now exists, either return it from DROP for the empty case or explicitly document why DROP keeps #N/A, and call out the SEQUENCE(0) error-type change in the changelog as a breaking change.
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).
### Context This PR adds the `TRIMRANGE` dynamic-array function (HF-391). `TRIMRANGE(range, [trim_rows], [trim_cols])` returns a range without the blank rows and columns at its edges. > [!IMPORTANT] > **Stacked on #1796 (`DROP`).** #1722 (`TAKE`) has merged. Until #1796 merges, this diff also shows its commits. Once it merges, `develop` will be merged into this branch and only these changes will remain in the diff. Behavior, checked against Microsoft Excel Online (en-US): - Each trim code is 0 (none), 1 (leading), 2 (trailing) or 3 (both, the default). Fractions, other numbers, text and `""` return `#VALUE!`; numeric text and `TRUE`/`FALSE` are accepted. - In a range, only an empty cell is blank. Formulas, empty text, 0, `FALSE`, errors and spaces are content, and blank cells inside the result stay blank. - A source with nothing left to keep returns `#REF!`. ### Implementation - `TRIMRANGE` lives in `ArrayPlugin`, after `TAKE`. Codes are read as single values and coerced in the method, so errors are reported in Excel's order. - The edges are found by scanning inward, so the cost is the blank border, not the whole range. - The whole-column rule is now one helper shared with `TAKE`. `TAKE`'s results are unchanged. - Included: the catalogue entry, the license table entry, the name in every language pack, the changelog and `list-of-differences.md` rows. Localized names come from Excel Online in each locale; Indonesian keeps the English name. ### How did you test your changes? - Tests PR: handsontable/hyperformula-tests#103, 142 tests from 143 cases measured in Microsoft Excel Online (en-US), plus scenario tests. - Full Jest suite after merging the current `feature/hf-384-drop`, which includes `develop`: 541 suites, 8,589 tests passed, 3 skipped. `TAKE` gave identical results on 540 probes before and after the shared helper. - Ten deliberate breaks of the code each failed tests, for example 37 when leading columns were not trimmed. - `npm run compile`, `npm run docs:generate-function-docs` and `git diff --check` pass. Lint shows no warnings on new lines. ### AI assistance Claude Code wrote the code, tests and docs. I reviewed it. ### Compatibility with Excel and Google Sheets Excel: Microsoft Excel Online (en-US). Google Sheets has no `TRIMRANGE` function. In the examples, A1:E6 holds 1, 2, 3 / 4, blank, 6 / 7, 8, 9 in B2:D4 with blank cells around it, O1:O4 is blank, and Q1:Q5 holds a blank cell, `=""`, 5, `=""` and a blank cell. | Formula | Excel | Google Sheets | HyperFormula | |---|---|---|---| | `=ROWS(TRIMRANGE(A1:E6))` | 3 | No such function | 3 | | `=TRIMRANGE(A1:E6,4)` | `#VALUE!` | No such function | `#VALUE!` | | `=TRIMRANGE(A1:E6,1.5)` | `#VALUE!` | No such function | `#VALUE!` | | `=ROWS(TRIMRANGE(O1:O4))` | `#REF!` | No such function | `#REF!` | | `=COUNTA(TRIMRANGE(Q1:Q5))` | 3 | No such function | 3 | Deliberate differences, listed in `list-of-differences.md`: | Case | HyperFormula | Excel | |---|---|---| | Result size | The untrimmed range is reserved; the result fills its top-left corner, the rest stays blank | Spills only the trimmed result and follows the data | | Whole column or row | Spills from the first row or column only, with the sheet's current size | Spills from any row | | Array or range as a trim code | One `#VALUE!` | An array of `#VALUE!` | | Result type | Values | A reference (`ISREF` is TRUE) | | `A1:.C10` trim references | Parse error | Supported | ### Public API changes None. One new built-in function. ### Out of scope and follow-ups The trim-reference syntax (`A1:.C10`) is not parsed; it needs parser support beyond this function. ### Types of changes - [ ] Breaking change (existing functionality no longer works as before) – agreed with the maintainers - [x] New feature or improvement (a non-breaking change that adds functionality) - [ ] Bug fix (a non-breaking change that fixes an issue) - [x] Additional language file, or a change to an existing language file (translations) - [x] Change to the documentation ### Related issues 1. HF-391 (`TRIMRANGE`). 2. Depends on #1796 (`DROP`). 3. Tests: handsontable/hyperformula-tests#103 ### Checklist - [x] My pull request meets the [Definition of Done](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DEFINITION-OF-DONE.md). External contributors: see also [Contributing to HyperFormula](https://handsontable.com/docs/hyperformula/guide/contributing.html). - [x] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [ ] I read my own diff end to end before requesting a review. - [x] I added a [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/develop/CHANGELOG.md) entry, written by [the changelog rules](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DOC-STANDARDS.md#the-changelog) – or none is needed (docs, tests or tooling only). - [x] I updated the documentation and JSDoc to match the change. - [ ] Breaking change only: I added a section to the migration guide. - [x] I updated the `dev-docs/` pages this change affects – or none needed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Large changes to array spill sizing and evaluation in the core interpreter path; incorrect prediction could cause wrong spill areas or `#SPILL`/`#N/A` behavior across dependent sheets. > > **Overview** > Adds Excel-style dynamic-array functions **`TAKE`**, **`DROP`**, and **`TRIMRANGE`** in `ArrayPlugin`, with evaluation, static spill-size prediction, and shared helpers for whole-column/row sources and sheet-edge placement (`sizeAtSheetEdge`, literal count parsing). > > **`TRIMRANGE`** trims blank edge rows/columns (configurable codes 0–3), scans content without reading whole ranges, reserves the full source footprint for spill (trimmed data in the top-left), and returns values rather than references. **`TAKE`** / **`DROP`** slice sources by row/column counts (including negative “from end” semantics); zero counts yield `#N/A` via new `ErrorMessage.ZeroRowOrColumnCount`. > > Spill behavior differs from Excel where documented: errors and cell-dependent counts fill or reserve the predicted array area (`#SPILL` when sizing runs before evaluation). **`Interpreter.isFunctionImplementedBy`** supports static analysis of count expressions (e.g. `TRUE`/`FALSE`). > > Also updates function metadata, license allowlists, localized names across language packs, **CHANGELOG**, and **`list-of-differences.md`** (including general rows on array errors and dynamic sizing). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7054e1d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Kuba Sekowski <kuba.sekowski.dev@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Kuba Sekowski <jakub.sekowski@handsontable.com>
…1830) ### Context This PR adds the `WRAPROWS`, `WRAPCOLS` and `EXPAND` dynamic-array functions (HF-390, HF-389, HF-386). `WRAPROWS(vector, wrap_count, [pad_with])` and `WRAPCOLS(vector, wrap_count, [pad_with])` wrap a row or column of values into rows or columns of `wrap_count` values. `EXPAND(array, rows, [columns], [pad_with])` pads an array to the given numbers of rows and columns. > [!IMPORTANT] > **Stacked on #1796 (`DROP`).** The three functions reuse the count parser and the whole-column size helper that #1796 and #1722 (merged) introduce, so this branch is based on `feature/hf-384-drop`. Until #1796 merges, this diff also shows its commits. Once it merges, `develop` will be merged into this branch and only these changes will remain in the diff. Behavior, checked against Microsoft Excel Online (en-US): - `WRAPROWS` fills rows and `WRAPCOLS` fills columns, in the vector's order; a row and a column vector give the same result. The last line is padded with `pad_with`, or with `#N/A` when the `pad_with` argument is omitted or left empty; a reference to an empty cell pads with blank cells, as in Excel. A `wrap_count` at least as large as the vector returns the vector at its own length, without padding. - `pad_with` can be any value, including an error or a blank cell, and is used only for padded cells: an error in `pad_with` never becomes the result. - `wrap_count` is truncated toward zero; a value below 1 (including `FALSE`, `0.5` and a blank cell) returns `#NUM!`. Numeric text, percentages and `TRUE` are accepted; `""`, an empty-text cell and other text return `#VALUE!`. - A two-dimensional `vector`, an empty `vector` argument and a blank one-cell `vector` return `#VALUE!`. Errors are reported in this order: the vector's error, the count's error or coercion, the vector's shape, then the count's range. - `EXPAND` pads with `pad_with`, with `#N/A` when it is omitted, and with blank cells when it is empty. An omitted or empty `rows` or `columns` keeps the array's size. Counts are truncated toward zero and coerced as `wrap_count`; a count smaller than the array returns `#VALUE!`, and more than 1,048,576 rows return `#NUM!`. An array or a range as `pad_with` returns `#VALUE!`. - Errors and blank cells inside the source stay elements of the result. Scalars, inline arrays, ranges and computed arrays are accepted as sources. The result is a value, not a reference, as in Excel. Differences from Excel, listed in `list-of-differences.md` unless noted: - A count read from a cell, or given as an array, makes the formula a single cell, as for `SEQUENCE`: the result's size must be known before the formula is evaluated, so a larger result returns `#VALUE!`. A one-cell result and every error are shown as in Excel. Excel wraps or expands by the cell's value, and lifts an array count into one result per element. - An array as `pad_with` in `WRAPROWS` and `WRAPCOLS` uses its first value; Excel returns one result per element. A two-cell range as a count or as `pad_with` returns `#VALUE!` when the formula is outside the range's rows; Excel lifts it as an array (not listed: a range where a single value is expected). - Whole-column and whole-row sources use the source sheet's current size, as in `TAKE` and `DROP`, and spill from the first row (or column) only; elsewhere they return `#SPILL!`, also for a whole column in column A below the first row and a whole row in the first row right of column A. `EXPAND` with an explicit `rows` pads a whole column to that many rows when the sheet is shorter; Excel counts all 1,048,576 rows and returns `#VALUE!`. - `EXPAND`, `WRAPROWS` and `WRAPCOLS` return `#VALUE!` for a result larger than the configured sheet size (the `maxRows` and `maxColumns` options), as `SEQUENCE` does, before building it. Excel returns the full result, for example 1,048,576 rows inside `ROWS`, or 20,000 columns for `=COLUMNS(WRAPCOLS(SEQUENCE(20000),1))`. #### Implementation - The three functions live in `ArrayPlugin`, after `TAKE`. `WRAPROWS` and `WRAPCOLS` share one implementation with the orientation as a parameter. - Counts are read as single values and coerced in the method, so that `""` returns `#VALUE!` and errors are reported in Excel's order. - Spill-size prediction uses literal counts and gives the exact size; a literal count that makes the function return an error returns that error instead of reserving space. A count that isn't a literal makes the formula a single cell (above). A source whose size can't be predicted before evaluation (a named expression), passed to `EXPAND` with a kept dimension, also makes it a single cell. - Whole-column and whole-row sources use the existing effective-size helper and `TAKE`'s placement rule. - VSTACK's row-padding helper takes an optional pad value, which the three functions use; VSTACK keeps padding with `#N/A`. - The function metadata catalogue entries, the changelog, and rows in `list-of-differences.md` are included. - Localized names were read from Excel Online in every locale by switching the session language and reading the formula bar. Indonesian keeps the English names, because Excel Online shows English function names in that locale. ### How did you test your changes? - Tests PR: handsontable/hyperformula-tests#98, branch `feature/HF-390`. It adds 126 `WRAPROWS`, 63 `WRAPCOLS` and 130 `EXPAND` tests, generated from 322 cases measured in Microsoft Excel Online (en-US) on the same data, plus tests for spill placement of whole columns and rows, counts read from cells, sources of unknown size and the configured sheet size. - Full Jest suite after merging the current `feature/hf-384-drop`, which includes `develop`: 543 suites, 8,766 tests passed, 3 skipped. The existing `TAKE`, `DROP`, `VSTACK` and `HSTACK` tests pass unchanged. - Breaking the code on purpose made the tests fail, for example: not capping a line at the vector's length failed 19 tests, not transposing `WRAPCOLS`'s predicted size failed 11, and accepting empty text as a count failed 7. The previous spill placement and the missing sheet-size check fail the 4 newest tests. - `npm run lint` reports no errors, and `npm run verify:typings` passes. ### AI assistance Claude Code wrote the code, tests and docs, and ran the Excel comparison. ### Compatibility with Excel and Google Sheets Checked in Microsoft Excel Online and Google Sheets, with 1 to 7 in A1:G1. Google Sheets has no `EXPAND` function. | Formula | Excel | Google Sheets | HyperFormula | |---|---|---|---| | `=WRAPROWS(A1:G1,3)` | `1, 2, 3; 4, 5, 6; 7, #N/A, #N/A` | same | same | | `=WRAPCOLS(A1:G1,3)` | `1, 4, 7; 2, 5, #N/A; 3, 6, #N/A` | same | same | | `=WRAPROWS({1,2,3},2,J1)`, J1 empty | `1, 2; 3, (blank)` | same | same | | `=WRAPROWS(K1,1)`, K1 = 0 | `0` | `0` | `0` | | `=EXPAND(A3:B4,3,3)`, 1, 2, 4, 5 in A3:B4 | `1, 2, #N/A; 4, 5, #N/A; #N/A, #N/A, #N/A` | No such function | same as Excel | | `=COLUMNS(WRAPCOLS(SEQUENCE(20000),1))` | `20000` | `20000` | `#VALUE!` (default `maxColumns` is 18,278) | The last row is a deliberate difference, listed in `list-of-differences.md` with the others above. ### Public API changes None. Three new built-in functions. ### Out of scope and follow-ups - Lifting an array count or an array `pad_with` into one result per element, as Excel does; HyperFormula sizes a spilled result before evaluating it. ### Types of changes - [ ] Breaking change (existing functionality no longer works as before) – agreed with the maintainers - [x] New feature or improvement (a non-breaking change that adds functionality) - [ ] Bug fix (a non-breaking change that fixes an issue) - [x] Additional language file, or a change to an existing language file (translations) - [x] Change to the documentation ### Related issues 1. HF-390, HF-389, HF-386. Depends on #1796 (`DROP`). 2. Tests: handsontable/hyperformula-tests#98 ### Checklist - [x] My pull request meets the [Definition of Done](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DEFINITION-OF-DONE.md). External contributors: see also [Contributing to HyperFormula](https://handsontable.com/docs/hyperformula/guide/contributing.html). - [x] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [ ] I read my own diff end to end before requesting a review. - [x] I added a [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/develop/CHANGELOG.md) entry, written by [the changelog rules](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DOC-STANDARDS.md#the-changelog) – or none is needed (docs, tests or tooling only). - [x] I updated the documentation and JSDoc to match the change. - [ ] Breaking change only: I added a section to the migration guide. - [x] I updated the `dev-docs/` pages this change affects – or none needed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Large changes to array spill reservation and evaluation in `ArrayPlugin`; incorrect size prediction can cause wrong spill behavior or performance on whole-sheet references, though behavior is heavily documented and tested externally. > > **Overview** > Adds five Excel-style **dynamic-array** lookup functions in **`ArrayPlugin`**: **`TAKE`** and **`DROP`** slice sources by row/column counts; **`WRAPROWS`** / **`WRAPCOLS`** reshape 1-D vectors with optional padding; **`EXPAND`** pads arrays to target dimensions. > > Implementation centers on **static spill-size prediction** (same model as **`SEQUENCE`**): literal counts get exact footprints; cell-dependent counts, oversized results vs **`maxRows`**/**`maxColumns`**, and whole-column/whole-row sources only spill from row/column 1—otherwise **`#SPILL!`** or **`#VALUE!`**. Array errors fill the pre-reserved spill area. Shared helpers cover literal count parsing, effective source sizing, slicing, and optional **`padRowToWidth`** padding (also used by **`VSTACK`**). > > Also adds **`ZeroRowOrColumnCount`** for zero **`TAKE`** dimensions, **`Interpreter.isFunctionImplementedBy`** for static **`TRUE`/`FALSE`** in count parsing, function metadata and license capability entries, localized names across language packs, changelog entries, and **`list-of-differences.md`** rows documenting Excel/Sheets parity gaps. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3ad7f8d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Kuba Sekowski <kuba.sekowski.dev@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Kuba Sekowski <jakub.sekowski@handsontable.com>
Context
This PR adds the
DROPdynamic-array function (HF-384).DROP(array, rows, [columns])removes rows or columns from the beginning (positive counts) or the end (negative counts) of an array and returns the rest.Behavior, checked against Excel:
FALSE, blank-cell, omitted, or empty count drops nothing and returns the whole array.#VALUE!, and an error in a count propagates.#N/Awith the message "Empty array not allowed.". Excel returns#CALC!, which HyperFormula does not have.Note: Microsoft's DROP page says a zero count returns
#CALC!. Excel actually returns the full array, and this implementation follows Excel.Implementation
DROPlives inArrayPlugin, next toTAKE. The two functions now share:parseLiteralCount, the static count parser (renamed fromparseTakeLiteralNumber);directSourceRange(renamed fromtakeSourceRange);effectiveSourceSize, which measures whole-column and whole-row sources;sliceSourceArray, which reads only the kept cells of an address-backed source and returns values rather than a range, so scalar coercion behaves like any other array result.TRUE()/FALSE(), parentheses, unary signs, percentages, or constant arithmetic. Dropped rows and columns are never reserved. Counts that depend on other cells reserve the source size as an upper bound, and invalid literal counts return their error instead of#SPILL!.=DROP(Data!A:A,1)fits in rows 1–2 and returns#SPILL!from row 3. A count from a cell isn't known when the spill is sized, so it follows the rule for a count of 0: the result fits only in the first row or column and returns#SPILL!below it. Excel still spills it when the formula is no lower than row count + 1; that difference is listed inlist-of-differences.md.list-of-differences.mdare included: two in the general table (an error as a count, and a result size that depends on a cell) and six forDROP(the empty result, whole-column spills with a literal count and with a count from a cell, a negative count over a whole column, array counts, and values rather than a reference).TAKE's name in the same locale (for exampleINCLUIR/EXCLUIRandAL/BIRAK). Indonesian keeps the English name because Google Sheets has noDROP.How did you test your changes?
feature/hf-384-drop. It adds 82DROPtests covering every case verified in Excel, spill-size prediction, whole-column and whole-row boundaries, lazy reads, use as an argument, and the documented negative-count difference.develop: 540 suites, 8,447 tests passed, 3 skipped. The existingTAKEtests pass unchanged after the helper refactor.npm run lintreports no errors, andnpm run verify:typingspasses.AI assistance
Claude Code wrote the code, tests and docs, and ran the Excel comparison.
Compatibility with Excel and Google Sheets
Checked in Microsoft Excel Online, 66
DROPcases, with 1..9 by rows in A1:C3. Google Sheets has noDROPfunction.=DROP(A1:C3,2)7, 8, 97, 8, 9=DROP(A1:C3,-1,-1)1, 2; 4, 51, 2; 4, 5=DROP(A1:C3,0)=DROP(A1:C3,1.9)4, 5, 6; 7, 8, 94, 5, 6; 7, 8, 9=DROP(A1:C3,3)#CALC!#N/A=SUM(DROP(A:A,-1)), 1..5 in A1:A5=ISREF(DROP(A1:C3,1))TRUEFALSEThe last three are deliberate differences, listed in
list-of-differences.mdwith the other fiveDROProws.Public API changes
None. One new built-in function.
Out of scope and follow-ups
DROPreturns#N/Afor an empty result until the#CALC!error lands (Add the #CALC! error type (HF-134) #1889); a follow-up then switches it, withTAKE.DROPorTAKEentered withsetCellContentsbelow its fit area returns a parsing error instead of#SPILL!; the same happens forFILTERandSORTondevelop, so it is out of scope here.Types of changes
Related issues
Checklist
dev-docs/pages this change affects – or none needed it.🤖 Generated with Claude Code
Note
Medium Risk
Touches core dynamic-array spill sizing and evaluation in
ArrayPlugin, where mistakes can cause incorrect#SPILL!behavior or wrong result dimensions; changes are additive but interact with existing TAKE helpers.Overview
Adds Excel-style
TAKEandDROPdynamic-array functions inArrayPlugin, with shared static count parsing, source sizing, and efficient array slicing for spill prediction and evaluation.DROP(array, rows, [columns])removes rows/columns from the start (positive) or end (negative), returns#N/Awhen nothing remains, and uses spill rules aligned with whole-column/whole-row sources—especially#SPILL!when counts come from cells after the spill size is fixed (documented vs Excel).Refactors
ArrayPluginwith helpers (parseLiteralCount,take/droparray-size methods,sliceSourceArray) and addsInterpreter.isFunctionImplementedByfor staticTRUE()/FALSE()counts. Registers both functions in metadata, license lists, changelog, compatibility docs, localized names, and the newZeroRowOrColumnCounterror for zeroTAKEdimensions.Reviewed by Cursor Bugbot for commit dc1b2da. Bugbot is set up for automated code reviews on this repo. Configure here.