Repository navigation
Fix TypeError when combining the text table strategy with text_layout - #1403
Open
MohammadHijjawi97 wants to merge 1 commit into
Open
MohammadHijjawi97 wants to merge 1 commit into
MohammadHijjawi97 wants to merge 1 commit into
Conversation
With the "text" table strategy, TableFinder passed every text_* setting to Page.extract_words(), so settings that only apply to text extraction (e.g., text_layout=True, as documented for table settings) raised "TypeError: WordExtractor.__init__() got an unexpected keyword argument". Only pass on the settings WordExtractor accepts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The table-extraction docs say that all
text_-prefixed settings are passed to text extraction, and that "All possible arguments toPage.extract_text(...)are also valid here." With the"text"strategy, though, some of them crash:The same happens with other extract_text-only arguments (e.g.
text_x_density,text_layout_width). With the default"lines"strategy, the same settings work fine.Cause
For the
"text"strategy,TableFinder.get_edges()callsself.page.extract_words(**settings.text_settings).extract_wordspasses everything toWordExtractor, which only accepts word-extraction arguments.Fix
When finding words for the text strategy, only pass on the
text_settingskeys thatWordExtractoraccepts. These are listed inutils.text.WORD_EXTRACTOR_KWARGS, whichchars_to_textmapandextract_textalready use for the same purpose. Cell text extraction still receives alltext_*settings, sotext_layoutetc. keep working there.Tests
test_text_layout_with_text_strategyintests/test_table.py, using the existingsenate-expenditures.pdf. It fails ondevelopwith theTypeErrorabove and passes with this change. It also checks that the layout-extracted cells, once stripped, match the non-layout ones.tests/test_table.pypasses.black --check,isort --check-only,flake8andmypy --strict --implicit-reexportall pass.CHANGELOG updated.