feat(python): support list of list fields from pydantic schema (#747)

For object detection, each row may correspond to an image and each image
can have multiple bounding boxes of x-y coordinates. This means that a
`bbox` field is potentially "list of list of float". This adds support
in our pydantic-pyarrow conversion for nested lists.
This commit is contained in:
Chang She
2023-12-27 09:10:09 -08:00
committed by Weston Pace
parent 4891a7ae14
commit 46bf5a1ed1
2 changed files with 16 additions and 1 deletions

View File

@@ -164,6 +164,9 @@ def _py_type_to_arrow_type(py_type: Type[Any]) -> pa.DataType:
return pa.date32()
elif py_type == datetime:
return pa.timestamp("us")
elif py_type.__origin__ in (list, tuple):
child = py_type.__args__[0]
return pa.list_(_py_type_to_arrow_type(child))
raise TypeError(
f"Converting Pydantic type to Arrow Type: unsupported type {py_type}"
)