From 67441ca4188d532c79df788c461e7f6f7d2f8170 Mon Sep 17 00:00:00 2001 From: Christoph Auer <60343111+cau-git@users.noreply.github.com> Date: Tue, 22 Jul 2025 17:02:12 +0200 Subject: [PATCH] fix: Keep formula clusters also when empty (#1970) Keep formula clusters also when empty Signed-off-by: Christoph Auer --- docling/utils/layout_postprocessor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docling/utils/layout_postprocessor.py b/docling/utils/layout_postprocessor.py index effce01b..edc6b396 100644 --- a/docling/utils/layout_postprocessor.py +++ b/docling/utils/layout_postprocessor.py @@ -267,9 +267,14 @@ class LayoutPostprocessor: # Initial cell assignment clusters = self._assign_cells_to_clusters(clusters) - # Remove clusters with no cells (if keep_empty_clusters is False) + # Remove clusters with no cells (if keep_empty_clusters is False), + # but always keep clusters with label DocItemLabel.FORMULA if not self.options.keep_empty_clusters: - clusters = [cluster for cluster in clusters if cluster.cells] + clusters = [ + cluster + for cluster in clusters + if cluster.cells or cluster.label == DocItemLabel.FORMULA + ] # Handle orphaned cells unassigned = self._find_unassigned_cells(clusters)