Skip to content

Commit

Permalink
Merge branch 'main' into feature/exclude-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
simw authored May 23, 2024
2 parents d2add23 + fe2cc1a commit 01b6c79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/pydantic_to_pyarrow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ def _get_dict_type(
)


def _get_dict_type(
field_type: Type[Any], metadata: List[Any], allow_losing_tz: bool
) -> pa.DataType:
key_type, value_type = get_args(field_type)
return pa.map_(
_get_pyarrow_type(key_type, metadata, allow_losing_tz=allow_losing_tz),
_get_pyarrow_type(value_type, metadata, allow_losing_tz=allow_losing_tz),
)


FIELD_TYPES = {
Literal: _get_literal_type,
list: _get_list_type,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class EnumModel(BaseModel):
with pytest.raises(SchemaCreationError):
get_pyarrow_schema(EnumModel)


def test_exclude_field_true() -> None:
class SimpleModel(BaseModel):
a: str
Expand Down Expand Up @@ -563,6 +563,8 @@ class SimpleModel(BaseModel):
actual = get_pyarrow_schema(SimpleModel)

assert actual == expected


def test_dict() -> None:
class DictModel(BaseModel):
foo: Dict[str, int]
Expand Down

0 comments on commit 01b6c79

Please sign in to comment.