Skip to content

Commit

Permalink
Add handling None input
Browse files Browse the repository at this point in the history
  • Loading branch information
plutasnyy committed Jan 17, 2025
1 parent 9719909 commit 9c68989
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 13 additions & 0 deletions test_unstructured/partition/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,19 @@ def test_auto_handles_kwarg_with_infer_table_structure(infer_bool):
assert mock_process_file_with_model.call_args[1]["infer_table_structure"] is infer_bool


def test_auto_handles_kwarg_with_infer_table_structure_when_none():
with patch(
"unstructured.partition.pdf_image.ocr.process_file_with_ocr",
) as mock_process_file_with_model:
partition(
example_doc_path("pdf/layout-parser-paper-fast.pdf"),
pdf_infer_table_structure=True,
strategy=PartitionStrategy.HI_RES,
infer_table_structure=None,
)
assert mock_process_file_with_model.call_args[1]["infer_table_structure"] is True


def test_auto_partition_pdf_uses_pdf_infer_table_structure_argument():
with patch(
"unstructured.partition.pdf_image.ocr.process_file_with_ocr",
Expand Down
10 changes: 6 additions & 4 deletions unstructured/partition/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ def partition(
# into a partition function, e.g., partition_email is reused to partition sub-elements, e.g.,
# partition an image attachment buy calling partition with the kwargs. In that case here kwargs
# would have a infer_table_structure already
infer_table_structure = kwargs.pop(
"infer_table_structure",
decide_table_extraction(
kwargs_infer_table_structure = kwargs.pop("infer_table_structure", None)
infer_table_structure = (
kwargs_infer_table_structure
if kwargs_infer_table_structure is not None
else decide_table_extraction(
file_type,
skip_infer_table_types,
pdf_infer_table_structure,
),
)
)

partitioner_loader = _PartitionerLoader()
Expand Down

0 comments on commit 9c68989

Please sign in to comment.