From 6905d86ffb83a838c74f89381a1c0af1a255e58f Mon Sep 17 00:00:00 2001 From: Christoph Auer Date: Tue, 22 Jul 2025 16:03:35 +0200 Subject: [PATCH] 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)