Skip to content

Commit

Permalink
Update README for list and add nested model to example
Browse files Browse the repository at this point in the history
  • Loading branch information
simw committed Nov 2, 2023
1 parent 27e9576 commit 0fa41b3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,35 @@ pydantic.types.AwareDatetime | pa.timestamp("ms", tz=None) ONLY if param allow_l
. | .
Optional[...] | The pyarrow field is nullable |
Pydantic Model | pa.struct() |

List[...] | pa.list_(...) |

## An Example

```py
from typing import Optional
from typing import List, Optional

from pydantic import BaseModel
from pydantic_to_pyarrow import get_pyarrow_schema

class NestedModel(BaseModel):
str_field: str


class MyModel(BaseModel):
int_field: int
opt_str_field: Optional[str]
py310_opt_str_field: str | None
nested: List[NestedModel]


pa_schema = get_pyarrow_schema(MyModel)
print(pa_schema)
#> int_field: int64 not null
#> opt_str_field: string
#> py310_opt_str_field: string
#> nested: list<item: struct<str_field: string not null>> not null
#> child 0, item: struct<str_field: string not null>
#> child 0, str_field: string not null
```

## Development
Expand Down

0 comments on commit 0fa41b3

Please sign in to comment.