-
Notifications
You must be signed in to change notification settings - Fork 8.2k
fix: Don't fail if doc column is missing #10746
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e25ef32
fix: Don't fail if doc column is missing
erichare cdcd96b
[autofix.ci] apply automated fixes
autofix-ci[bot] 476468d
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] 2e79019
Surface warning message to the UI
erichare df3822a
Merge branch 'main' into fix-docling-doc-error
erichare 7c59664
[autofix.ci] apply automated fixes
autofix-ci[bot] 1ab0569
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] a86364e
Update test_docling_utils.py
erichare 4a6b8c0
[autofix.ci] apply automated fixes
autofix-ci[bot] ef9b881
Update test_docling_utils.py
erichare 16a18cf
Merge branch 'main' into fix-docling-doc-error
erichare 9bd54dd
Merge branch 'main' into fix-docling-doc-error
erichare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """Tests for docling_utils module.""" | ||
|
|
||
| import pytest | ||
| from docling_core.types.doc import DoclingDocument | ||
| from lfx.base.data.docling_utils import extract_docling_documents | ||
| from lfx.schema.data import Data | ||
| from lfx.schema.dataframe import DataFrame | ||
|
|
||
|
|
||
| class TestExtractDoclingDocuments: | ||
| """Test extract_docling_documents function.""" | ||
|
|
||
| def test_extract_from_data_with_correct_key(self): | ||
| """Test extracting DoclingDocument from Data with correct key.""" | ||
| # Create a mock DoclingDocument | ||
| doc = DoclingDocument(name="test_doc") | ||
| data = Data(data={"doc": doc, "file_path": "test.pdf"}) | ||
|
|
||
| # Extract documents | ||
| result = extract_docling_documents(data, "doc") | ||
|
|
||
| # Verify | ||
| assert len(result) == 1 | ||
| assert isinstance(result[0], DoclingDocument) | ||
| assert result[0].name == "test_doc" | ||
|
|
||
| def test_extract_from_data_with_wrong_key(self): | ||
| """Test extracting DoclingDocument from Data with wrong key raises error.""" | ||
| doc = DoclingDocument(name="test_doc") | ||
| data = Data(data={"doc": doc, "file_path": "test.pdf"}) | ||
|
|
||
| # Should raise TypeError when key is not found | ||
| with pytest.raises(TypeError, match="'wrong_key' field not available"): | ||
| extract_docling_documents(data, "wrong_key") | ||
|
|
||
| def test_extract_from_list_of_data(self): | ||
| """Test extracting DoclingDocument from list of Data objects.""" | ||
| doc1 = DoclingDocument(name="test_doc1") | ||
| doc2 = DoclingDocument(name="test_doc2") | ||
| data_list = [ | ||
| Data(data={"doc": doc1, "file_path": "test1.pdf"}), | ||
| Data(data={"doc": doc2, "file_path": "test2.pdf"}), | ||
| ] | ||
|
|
||
| # Extract documents | ||
| result = extract_docling_documents(data_list, "doc") | ||
|
|
||
| # Verify | ||
| assert len(result) == 2 | ||
| assert all(isinstance(d, DoclingDocument) for d in result) | ||
| assert result[0].name == "test_doc1" | ||
| assert result[1].name == "test_doc2" | ||
|
|
||
| def test_extract_from_dataframe_with_correct_column(self): | ||
| """Test extracting DoclingDocument from DataFrame with correct column name.""" | ||
| doc1 = DoclingDocument(name="test_doc1") | ||
| doc2 = DoclingDocument(name="test_doc2") | ||
|
|
||
| # Create DataFrame with 'doc' column | ||
| df = DataFrame([{"doc": doc1, "file_path": "test1.pdf"}, {"doc": doc2, "file_path": "test2.pdf"}]) | ||
|
|
||
| # Extract documents | ||
| result = extract_docling_documents(df, "doc") | ||
|
|
||
| # Verify | ||
| assert len(result) == 2 | ||
| assert all(isinstance(d, DoclingDocument) for d in result) | ||
|
|
||
| def test_extract_from_dataframe_with_fallback_column(self): | ||
| """Test extracting DoclingDocument from DataFrame when exact column name not found but DoclingDocument exists.""" | ||
| doc1 = DoclingDocument(name="test_doc1") | ||
| doc2 = DoclingDocument(name="test_doc2") | ||
|
|
||
| # Create DataFrame where DoclingDocument is in a different column | ||
| # Simulate the case where pandas doesn't preserve the 'doc' column name | ||
| df = DataFrame([{"document": doc1, "file_path": "test1.pdf"}, {"document": doc2, "file_path": "test2.pdf"}]) | ||
|
|
||
| # Extract documents - should find 'document' column as fallback | ||
| result = extract_docling_documents(df, "doc") | ||
|
|
||
| # Verify | ||
| assert len(result) == 2 | ||
| assert all(isinstance(d, DoclingDocument) for d in result) | ||
erichare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_extract_from_dataframe_no_docling_column(self): | ||
| """Test extracting DoclingDocument from DataFrame with no DoclingDocument column raises helpful error.""" | ||
| # Create DataFrame without any DoclingDocument objects | ||
| df = DataFrame([{"text": "hello", "file_path": "test1.pdf"}, {"text": "world", "file_path": "test2.pdf"}]) | ||
|
|
||
| # Should raise TypeError with helpful message | ||
| with pytest.raises(TypeError) as exc_info: | ||
| extract_docling_documents(df, "doc") | ||
|
|
||
| # Verify error message contains helpful information | ||
| error_msg = str(exc_info.value) | ||
| assert "Column 'doc' not found in DataFrame" in error_msg | ||
| assert "Available columns:" in error_msg | ||
| assert "Possible solutions:" in error_msg | ||
| assert "Use the 'Data' output" in error_msg | ||
|
|
||
| def test_extract_from_empty_dataframe(self): | ||
| """Test extracting from empty DataFrame raises error.""" | ||
| df = DataFrame([]) | ||
|
|
||
| with pytest.raises(TypeError, match="DataFrame is empty"): | ||
| extract_docling_documents(df, "doc") | ||
|
|
||
| def test_extract_from_empty_data_list(self): | ||
| """Test extracting from empty list raises error.""" | ||
| with pytest.raises(TypeError, match="No data inputs provided"): | ||
| extract_docling_documents([], "doc") | ||
|
|
||
| def test_extract_from_none(self): | ||
| """Test extracting from None raises error.""" | ||
| with pytest.raises(TypeError, match="No data inputs provided"): | ||
| extract_docling_documents(None, "doc") | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
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.
We need to surface this to the UI
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.
@ogabrielluiz how does it look now?