-
Notifications
You must be signed in to change notification settings - Fork 148
[SNOW-3203938] Fix ai_parse_document_basic test #4109
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1070,8 +1070,49 @@ def test_dataframe_ai_transcribe_default_output_column(session, resources_path): | |
| assert all("start" in s and "end" in s for s in data["segments"]) | ||
|
|
||
|
|
||
| def test_dataframe_ai_parse_document_basic(session, resources_path): | ||
| """Test DataFrame.ai.parse_document OCR on a PDF document.""" | ||
| def test_dataframe_ai_parse_document_basic_legacy(session, resources_path): | ||
| """Test DataFrame.ai.parse_document OCR on a PDF document. | ||
| This test covers legacy behavior (post error handling changes, metadata is present in response).""" | ||
| session.sql( | ||
| "ALTER SESSION SET AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR = FALSE" | ||
| ).collect() | ||
|
Comment on lines
+1076
to
+1078
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we normally do not do this because our tests run in parallel and it might pollute other test
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So how can I control the behaviour based on the parameter? Should there be an assumption that moving forward metadata won't be at top level so the check should be simply removed (even though for some accounts it can still be here?). |
||
| try: | ||
| stage_name = Utils.random_stage_name() | ||
| _ = session.sql( | ||
| f"CREATE OR REPLACE TEMP STAGE {stage_name} ENCRYPTION = (TYPE = 'SNOWFLAKE_SSE')" | ||
| ).collect() | ||
| file_local = TestFiles(resources_path).test_doc_pdf | ||
| _ = session.file.put(file_local, f"@{stage_name}", auto_compress=False) | ||
|
|
||
| df = session.create_dataframe( | ||
| [[f"@{stage_name}/doc.pdf"]], schema=["file_path"] | ||
| ) | ||
|
|
||
| result_df = df.ai.parse_document( | ||
| input_column=to_file(col("file_path")), | ||
| output_column="parsed", | ||
| mode="OCR", | ||
| ) | ||
|
|
||
| assert result_df.columns == ["FILE_PATH", "PARSED"] | ||
|
|
||
| results = result_df.collect() | ||
| data = json.loads(results[0]["PARSED"]) if results[0]["PARSED"] else {} | ||
| assert isinstance(data, dict) | ||
| assert "content" in data and isinstance(data["content"], str) | ||
| assert isinstance(data.get("metadata", {}), dict) | ||
| if "metadata" in data and "pageCount" in data["metadata"]: | ||
| assert data["metadata"].get("pageCount", 0) >= 3 | ||
| finally: | ||
| session.sql( | ||
| "ALTER SESSION SET AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR = TRUE" | ||
| ).collect() | ||
|
|
||
|
|
||
| def test_dataframe_ai_parse_document_basic_new_eh(session, resources_path): | ||
| """Test DataFrame.ai.parse_document OCR on a PDF document. | ||
| This test covers legacy behavior (post error handling changes, metadata is absent in response).""" | ||
|
|
||
| stage_name = Utils.random_stage_name() | ||
| _ = session.sql( | ||
| f"CREATE OR REPLACE TEMP STAGE {stage_name} ENCRYPTION = (TYPE = 'SNOWFLAKE_SSE')" | ||
|
|
@@ -1093,9 +1134,6 @@ def test_dataframe_ai_parse_document_basic(session, resources_path): | |
| data = json.loads(results[0]["PARSED"]) if results[0]["PARSED"] else {} | ||
| assert isinstance(data, dict) | ||
| assert "content" in data and isinstance(data["content"], str) | ||
| assert isinstance(data.get("metadata", {}), dict) | ||
| if "metadata" in data and "pageCount" in data["metadata"]: | ||
| assert data["metadata"].get("pageCount", 0) >= 3 | ||
|
|
||
|
|
||
| def test_dataframe_ai_parse_document_default_output_column(session, resources_path): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.