-
Notifications
You must be signed in to change notification settings - Fork 836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix IndexError
when partioning a pdf with starting_page_number
#3246
Conversation
The Issue: When extracting images from pdfs, we use the metadata page number to index into a list of the images. However, the metadata page number can now be changed via `starting_page_number`. To get the true page index, we need to subtract this value. Testing: Run this snippet in a python shell. Before the fix, this throws an IndexError. On this branch, it will return the elements. ``` from unstructured.partition.auto import partition filename = "example-docs/layout-parser-paper-with-table.pdf" partition(filename, strategy="hi_res", extract_image_block_types=["Image", "Table"], starting_page_number=20) ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just requesting one additional test assertion.
@@ -1223,6 +1223,8 @@ def test_partition_pdf_element_extraction( | |||
if file_mode == "filename": | |||
elements = pdf.partition_pdf( | |||
filename=filename, | |||
# Image extraction shouldn't break by setting this | |||
starting_page_number=20, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add a test that asserts that the resulting page number in metadata
is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
starting_page_number
IndexError
when partioning a pdf with starting_page_number
The Issue:
When extracting images from pdfs, we use the metadata page number to index into a list of the images. However, the metadata page number can now be changed via
starting_page_number
. To get the true page index, we need to subtract this value.Testing:
Run this snippet in a python shell. Before the fix, this throws an IndexError. On this branch, it will return the elements.