fix: 遗留清理(枚举同源/边界防御/断言补强)
This commit is contained in:
@@ -54,7 +54,7 @@ class ExtractionMethod(Enum):
|
||||
class Provenance:
|
||||
file_name: str
|
||||
sheet_name: str
|
||||
row: int
|
||||
row: int # 数据行号(从 1 起:表格为物理行-表头行;自由文本为块序)
|
||||
column: str
|
||||
column_header: str
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from genesis.data_models import CellValue, ExcelTable, Provenance, SheetType
|
||||
from genesis.data_models import CellValue, ExcelTable, ExtractionMethod, Provenance, SheetType
|
||||
|
||||
|
||||
def extract_text_blocks(matrix: list[list[Any]]) -> list[str]:
|
||||
@@ -45,7 +45,7 @@ def build_free_text_table(
|
||||
return ExcelTable(
|
||||
name=sheet_name,
|
||||
detected_type=detected_type,
|
||||
extraction_method="llm_from_free_text",
|
||||
extraction_method=ExtractionMethod.LLM_FROM_FREE_TEXT.value,
|
||||
headers=["text"],
|
||||
rows=rows,
|
||||
)
|
||||
@@ -10,7 +10,10 @@ def forward_fill(
|
||||
"""合并单元格:用左上角主格值填充范围内全部单元格。"""
|
||||
out = [list(row) for row in matrix]
|
||||
for (min_row, min_col, max_row, max_col) in merged_ranges:
|
||||
if not out or min_row > len(out) or min_col > len(out[min_row - 1]):
|
||||
# 防御:合并范围 1-based,非法(<1)或越界时跳过该范围
|
||||
if not out or min_row < 1 or min_col < 1:
|
||||
continue
|
||||
if min_row > len(out) or min_col > len(out[min_row - 1]):
|
||||
continue
|
||||
main_value = out[min_row - 1][min_col - 1]
|
||||
for r in range(min_row, min(max_row, len(out)) + 1):
|
||||
|
||||
@@ -2,7 +2,9 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from genesis.data_models import CellFormatting, CellValue, ExcelTable, Provenance, SheetType
|
||||
from genesis.data_models import (
|
||||
CellFormatting, CellValue, ExcelTable, ExtractionMethod, Provenance, SheetType,
|
||||
)
|
||||
|
||||
|
||||
def column_letter(index: int) -> str:
|
||||
@@ -29,8 +31,10 @@ def extract_table(
|
||||
if not matrix:
|
||||
return ExcelTable(
|
||||
name=sheet_name, detected_type=detected_type,
|
||||
extraction_method="openpyxl", headers=[], rows=[],
|
||||
extraction_method=ExtractionMethod.OPENPYXL.value, headers=[], rows=[],
|
||||
)
|
||||
if header_row < 0 or header_row >= len(matrix):
|
||||
header_row = 0
|
||||
fmt_map = formatting_map or {}
|
||||
headers = [str(c) if c is not None else "" for c in matrix[header_row]]
|
||||
rows = []
|
||||
@@ -52,5 +56,5 @@ def extract_table(
|
||||
rows.append(row_dict)
|
||||
return ExcelTable(
|
||||
name=sheet_name, detected_type=detected_type,
|
||||
extraction_method="openpyxl", headers=headers, rows=rows,
|
||||
extraction_method=ExtractionMethod.OPENPYXL.value, headers=headers, rows=rows,
|
||||
)
|
||||
Reference in New Issue
Block a user