Skip to content

fix: fix multiple values for infer_table_structure - #3870

Merged
badGarnet merged 5 commits into
mainfrom
fix/double-infer-table-structure-kwarg
Jan 17, 2025
Merged

badGarnet merged 5 commits into
mainfrom
fix/double-infer-table-structure-kwarg

Conversation

@badGarnet

Copy link
Copy Markdown
Collaborator

This PR fixes a bug when using partition to partition an email with image attachments with hi_res and allow table structure inference -> the partitioning of the image would encounter a value error: got multiple values for keyword argument 'infer_table_structure'.

This is because pass kwargs into partition "other" types of files in this block infer_table_structure is packaged into partitioning_kwargs. Then for email at least when there are attachments that can be partitioned with hi_res we pass that dict of kwargs right back into partition entry -> so when we get here we are both specifying explicitly infer_table_structure and have it in kwargs variable

The fix is to detect first if kwargs already contains infer_table_structure and if yes use that and pop it from kwargs.

@sentry

sentry Bot commented Jan 17, 2025

Copy link
Copy Markdown

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: unstructured/partition/auto.py

Function Unhandled Issue
partition UnsupportedFileFormatError: Invalid file. The FileType.ZIP file type is not supported in partition. ...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

@badGarnet
badGarnet requested review from christinestraub, plucinskik and scanny and removed request for christinestraub, plucinskik and scanny January 17, 2025 02:42
Comment thread unstructured/partition/auto.py Outdated
# 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(

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.

Looking at the failing test I think we introduced a regression, and I believe this is because the below behaviour

>>> x={'a': None, 'b': 2}
>>> x
{'a': None, 'b': 2}
>>> a=x.pop('a', 5)
>>> b=x.pop('b', 5)
>>> a
>>> b
2

general_partition methods configure all parameters regardless of whether they are passed or not, so I assume it passed some Nones.

I modified that and added test

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.

It didn't change the ingest test, although maybe it is safer this way

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks for the catch

christinestraub and others added 2 commits January 17, 2025 08:06
…tures update (#3874)

This pull request includes updated ingest test fixtures.
Please review and merge if appropriate.

Co-authored-by: christinestraub <[email protected]>
@badGarnet
badGarnet requested review from ajjimeno and tbs17 January 17, 2025 18:18

@tbs17 tbs17 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.

LGTM!

@badGarnet
badGarnet added this pull request to the merge queue Jan 17, 2025

@ajjimeno ajjimeno 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.

LGTM!

Merged via the queue into main with commit 27cd53b Jan 17, 2025
@badGarnet
badGarnet deleted the fix/double-infer-table-structure-kwarg branch January 17, 2025 19:20
temp-adelyn pushed a commit to temp-adelyn/unstructured that referenced this pull request Mar 3, 2025
)

This PR fixes a bug when using `partition` to partition an email with
image attachments with hi_res and allow table structure inference -> the
partitioning of the image would encounter a value error: `got multiple
values for keyword argument 'infer_table_structure'`.

This is because pass `kwargs` into partition "other" types of files in
this
[block](https://github.com/Unstructured-IO/unstructured/blob/aa5f4015bf15cf5b79ac3e210b098148b75d9a5f/unstructured/partition/auto.py#L270-L280)
`infer_table_structure` is packaged into `partitioning_kwargs`. Then for
email at least when there are attachments that can be partitioned with
`hi_res` we pass that dict of `kwargs` right back into `partition` entry
-> so when we get
[here](https://github.com/Unstructured-IO/unstructured/blob/aa5f4015bf15cf5b79ac3e210b098148b75d9a5f/unstructured/partition/auto.py#L222-L235)
we are both specifying explicitly `infer_table_structure` and have it in
`kwargs` variable

The fix is to detect first if `kwargs` already contains
`infer_table_structure` and if yes use that and pop it from `kwargs`.

---------

Co-authored-by: Kamil Plucinski <[email protected]>
Co-authored-by: christinestraub <[email protected]>
Co-authored-by: ryannikolaidis <[email protected]>
Co-authored-by: christinestraub <[email protected]>
cragwolfe pushed a commit that referenced this pull request Oct 23, 2026
)

**Summary**

`partition_tsv()` silently ignores `infer_table_structure=False`, so
callers still receive `Table.metadata.text_as_html`. The flag is passed
through by `partition()` but absorbed by `**kwargs` in the TSV
partitioner.

The fix adds the explicit parameter with the same default (`True`) as
the other table partitioners, and sets HTML metadata only when enabled.
Tests cover both flag values through `partition_tsv()` and
`partition()`.

Disabling HTML sends the whole flattened table through the shared text
splitter, which exposed latent progress and work-bound defects in that
path. The branch therefore also carries the bounded-split fixes already
discussed on this PR: a prefix wholly covered by overlap advances, the
token window and fallback scans are bounded, the vocabulary bound is
shared across HTML cells, the unread suffix is not re-encoded on every
split, and a fitting input is not rejected because an earlier prefix
overflowed.

**This revision (`f256ed23`)**

Both findings from the latest review:

- **Preferred-separator search:** candidates inside one whitespace run
all trim to the same fragment and lstrip to the same remainder. The run
is now evaluated once and the remaining matches inside it are skipped,
so `"a" + " " * 100_000 + "print(1)"` measures one candidate instead of
100,000. Covered for spaces, newlines, mixed whitespace and a configured
tab separator.
- **Fallback overlap:** `split_pos > len(fragment)` records that the cut
trimmed a trailing whitespace run. That is now combined with
`is_whitespace_split`, so the overlap tail gets a separating space when
either side of the cut had whitespace. The corrupted `"aprint(1)"`
expectation is replaced by `"a print(1)"`; an unbroken-word test still
forbids an artificial space when the cut had no whitespace.

**Test**

- `pytest test_unstructured/chunking
test_unstructured/partition/test_tsv.py -q` → `719 passed, 2 skipped in
12.76s`
- `ruff check` and `ruff format --check` on the two changed files →
clean
- `git diff --check` → clean

Not run: the full partitioner/extras suites and cross-platform tests. CI
is now running on this head; no green check is claimed yet.

**Type of change:** bug fix; no new dependency. Related #4373 changes
numeric HTML generation, and #3870 fixed a duplicate auto-dispatch
kwarg; neither addresses this ignored TSV flag.
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.

6 participants