handsontable / handsontable/hyperformula

addColumns throws an error with AlwaysDense address mapping with empty values

Open
#1,027 1 comment 0 reactions 1 assignee View on GitHub

@sequba is already working on this.

Since Jul 11, 2022.

Bug Impact: Medium
Dominant language
TypeScript
Stars
2.8k
Forks
171
Avg merge
1d 22h
Merged PRs (30d)
7

Description

Calling addColumns does not work with the address mapping option AlwaysDense but works with AlwaysSparse. An error is only thrown when using buildEmpty as opposed to using buildFromArray. The test also appears to fail even when inserting columns into an index other than 0 so long as there are empty cell values in the index of the column that is being inserted.

Build Empty

Test with "AlwaysDense" throws an error
Test with "AlwaysSparse" succeeds

const engine = HyperFormula.buildEmpty({ chooseAddressMappingPolicy: new AlwaysDense() });
engine.addSheet();
engine.setCellContents({ col: 0, row: 0, sheet: 0 }, 1);
engine.setCellContents({ col: 0, row: 1, sheet: 0 }, 2);
engine.setCellContents({ col: 0, row: 5, sheet: 0 }, 5);
engine.addColumns(0, [0, 1]);

Error:

TypeError: Cannot read properties of undefined (reading 'splice')
 ❯ DenseStrategy.addColumns node_modules/hyperformula/commonjs/DependencyGraph/AddressMapping/DenseStrategy.js:153:45
 ❯ AddressMapping.addColumns node_modules/hyperformula/commonjs/DependencyGraph/AddressMapping/AddressMapping.js:278:20
 ❯ node_modules/hyperformula/commonjs/DependencyGraph/DependencyGraph.js:809:31
 ❯ EmptyStatistics.measure node_modules/hyperformula/commonjs/statistics/Statistics.js:114:20
 ❯ DependencyGraph.addColumns node_modules/hyperformula/commonjs/DependencyGraph/DependencyGraph.js:808:18
 ❯ Operations.doAddColumns node_modules/hyperformula/commonjs/Operations.js:1152:57
 ❯ Operations.addColumns node_modules/hyperformula/commonjs/Operations.js:315:16
 ❯ CrudOperations.addColumns node_modules/hyperformula/commonjs/CrudOperations.js:139:23
 ❯ HyperFormula.addColumns node_modules/hyperformula/commonjs/HyperFormula.js:1577:66
  • HyperFormula version: 2.0.0
  • Operating System: MacOS M1
When using build from array both address mapping options succeed
const engine = HyperFormula.buildFromArray([[1], [2], [], [], [], [5]], {
    chooseAddressMappingPolicy: new AlwaysDense(),
});
engine.addColumns(0, [0, 1]);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.