Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3120,11 +3120,11 @@ def __init__(self, **kwargs):
@classmethod
def _from_generated(cls, cell):
return cls(
kind=cell.kind,
kind=cell.kind if cell.kind else "content",
row_index=cell.row_index,
column_index=cell.column_index,
row_span=cell.row_span,
column_span=cell.column_span,
row_span=cell.row_span if cell.row_span else 1,
column_span=cell.column_span if cell.column_span else 1,
content=cell.content,
bounding_regions=[
BoundingRegion._from_generated(region)
Expand Down Expand Up @@ -3184,11 +3184,11 @@ def from_dict(cls, data):
:rtype: DocumentTableCell
"""
return cls(
kind=data.get("kind", None),
kind=data.get("kind", "content"),
row_index=data.get("row_index", None),
column_index=data.get("column_index", None),
row_span=data.get("row_span", None),
column_span=data.get("column_span", None),
row_span=data.get("row_span", 1),
column_span=data.get("column_span", 1),
content=data.get("content", None),
bounding_regions=[BoundingRegion.from_dict(v) for v in data.get("bounding_regions")] # type: ignore
if len(data.get("bounding_regions", [])) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,57 @@ def test_document_table_cell_to_dict(self):

assert d == final

def test_document_table_cell_to_dict_use_defaults(self):
# NOTE: kind, column_span, and row_span are not included on purpose to test that the proper defaults are set.
model = _models.DocumentTableCell(
row_index=2,
column_index=3,
content="cell content",
bounding_regions=[
_models.BoundingRegion(
bounding_box=[_models.Point(1, 2), _models.Point(3, 4)],
page_number=1,
),
],
spans=[
_models.DocumentSpan(
offset=5,
length=2,
),
],
)

d = model.to_dict()

final = {
"kind": "content",
"row_index": 2,
"column_index": 3,
"row_span": 1,
"column_span": 1,
"content": "cell content",
"bounding_regions": [
{
"page_number": 1,
"bounding_box": [
{"x": 1, "y": 2},
{
"x": 3,
"y": 4,
},
],
},
],
"spans": [
{
"offset": 5,
"length": 2,
},
],
}

assert d == final

def test_model_operation_info_to_dict(self):
model = _models.ModelOperationInfo(
operation_id="id123",
Expand Down