Skip to content

fix(types_doc): select removed table rows by cell offsets - #927

Open
simpleqt wants to merge 1 commit into
docling-project:mainfrom
simpleqt:fix/remove-rows-spanning-cells
Open

simpleqt wants to merge 1 commit into
docling-project:mainfrom
simpleqt:fix/remove-rows-spanning-cells

Conversation

@simpleqt

Copy link
Copy Markdown
Contributor

What

TableData.remove_rows() selected the cells of a row with table_cells[row_index * num_cols : (row_index + 1) * num_cols] and then rewrote the row offsets of the surviving cells with index // num_cols. Both steps assume that table_cells is a dense, row-major array.

A table with a spanning cell has fewer cells than num_rows * num_cols, so for such a table the slice returns cells of the following rows and the renumbering destroys the offsets of the remaining cells.

How

Select the cells by their row offsets. A cell that lives in the removed row only is removed; a cell that only partly covers the removed row keeps its content and its row span shrinks by one; cells below the removed row shift both row offsets by one. The position-based renumbering loop is removed, so column spans and column offsets survive.

Repro (before)

A 3x2 table whose row 0 is one header cell spanning both columns:

data.remove_rows([0])
# removed: [['SPAN', 'r1c0']]   <- 'r1c0' belongs to row 1
# grid:    [['r2c0', 'r1c1'], ['', 'r2c1']]   <- mixed rows, lost content

After the fix: removed == [['SPAN']], grid == [['r1c0', 'r1c1'], ['r2c0', 'r2c1']].

Tests

tests/test_docling_doc.py::test_table_remove_rows_keeps_spanning_cells (fails on main, passes with the fix). Dense tables keep their previous behaviour: remove_rows([1, 1]) on a 4x2 table is unchanged.

TableData.remove_rows sliced table_cells by position (row_index * num_cols).
That assumes a dense, row-major cell list. A table with a spanning cell holds
fewer cells than num_rows * num_cols, so the slice took cells of the following
rows and the renumbering step rewrote every row offset by list position. The
removed row then held foreign cells and the grid mixed content of different
rows.

Select the cells by their row offsets instead, and shrink the row span of a
cell that only partly covers the removed row. The result matches the previous
behaviour for dense tables.

Signed-off-by: simpleqt <89645338+simpleqt@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 13:53
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @simpleqt, all your commits are properly signed off. 🎉

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@mergify

mergify Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

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.

2 participants