mirror of
https://github.com/run-llama/llama_cloud_services.git
synced 2026-07-19 08:34:12 -04:00
Add new fields to SpreadsheetParsingConfig and update validation tests (#1042)
This commit is contained in:
committed by
GitHub
parent
e5dcaa83df
commit
06c3c556e6
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"llama-cloud-services-py": patch
|
||||
---
|
||||
|
||||
Update spreadsheet parsing config
|
||||
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
|
||||
@@ -63,7 +64,7 @@ class SpreadsheetParseResult(BaseModel):
|
||||
class SpreadsheetParsingConfig(BaseModel):
|
||||
"""Configuration for spreadsheet parsing and region extraction"""
|
||||
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
sheet_names: list[str] | None = Field(
|
||||
default=None,
|
||||
@@ -86,6 +87,16 @@ class SpreadsheetParsingConfig(BaseModel):
|
||||
description="Enables experimental processing. Accuracy may be impacted.",
|
||||
)
|
||||
|
||||
flatten_hierarchical_tables: bool = Field(
|
||||
default=False,
|
||||
description="Return a flattened dataframe when a detected table is recognized as hierarchical.",
|
||||
)
|
||||
|
||||
table_merge_sensitivity: Literal["strong", "weak"] = Field(
|
||||
default="strong",
|
||||
description="Influences how likely similar-looking regions are merged into a single table. Useful for spreadsheets that either have sparse tables (strong merging) or many distinct tables close together (weak merging).",
|
||||
)
|
||||
|
||||
|
||||
class SpreadsheetJob(BaseModel):
|
||||
"""A spreadsheet parsing job"""
|
||||
|
||||
@@ -2,11 +2,45 @@ import os
|
||||
import tempfile
|
||||
import pytest
|
||||
import pandas as pd
|
||||
from pydantic import ValidationError
|
||||
|
||||
from llama_cloud_services.beta.sheets import LlamaSheets
|
||||
from llama_cloud_services.beta.sheets.types import SpreadsheetParsingConfig
|
||||
|
||||
|
||||
class TestSpreadsheetParsingConfig:
|
||||
"""Unit tests for SpreadsheetParsingConfig."""
|
||||
|
||||
def test_default_values(self):
|
||||
"""Test that default values are set correctly."""
|
||||
config = SpreadsheetParsingConfig()
|
||||
assert config.flatten_hierarchical_tables is False
|
||||
assert config.table_merge_sensitivity == "strong"
|
||||
|
||||
def test_custom_values(self):
|
||||
"""Test setting custom values for new fields."""
|
||||
config = SpreadsheetParsingConfig(
|
||||
flatten_hierarchical_tables=True,
|
||||
table_merge_sensitivity="weak",
|
||||
)
|
||||
assert config.flatten_hierarchical_tables is True
|
||||
assert config.table_merge_sensitivity == "weak"
|
||||
|
||||
def test_table_merge_sensitivity_validation(self):
|
||||
"""Test that invalid table_merge_sensitivity values are rejected."""
|
||||
with pytest.raises(ValidationError):
|
||||
SpreadsheetParsingConfig(table_merge_sensitivity="invalid")
|
||||
|
||||
def test_unknown_fields_ignored(self):
|
||||
"""Test that unknown fields are silently ignored."""
|
||||
config = SpreadsheetParsingConfig(
|
||||
unknown_field="test",
|
||||
another_unknown=123,
|
||||
)
|
||||
assert not hasattr(config, "unknown_field")
|
||||
assert not hasattr(config, "another_unknown")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sheets_client():
|
||||
"""Create a LlamaSheets client for testing."""
|
||||
|
||||
Reference in New Issue
Block a user