Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for dictionary field type as pyarrow map array #13

Merged
merged 2 commits into from
May 23, 2024

Conversation

mae5357
Copy link
Contributor

@mae5357 mae5357 commented May 13, 2024

issue

Need support for python's dictionary type to convert pydantic object to pyarrow.

e.g.

MyModel(BaseModel):
    foo: Dict[str, str]

get_pyarrow_schema(MyModel)

change

If a pydantic field is defined as a Dict, convert to pyarrow.MapType [definition].

MapType is the closest pyarrow data type to the Dict type. However, it will convert to a tuple upon deserialization (from pyarrow to vanilla python).
https://arrow.apache.org/docs/python/data.html#map-arrays

note: this is a rather naive approach. open to suggestions... by default, pyarrow will try to use pyarrow.StructScalar. However, this will not work if inferring the schema of a Dict of unknown size.

test

assert the additional logic makes sense. assert the new test case passes.

@simw simw merged commit fe2cc1a into simw:main May 23, 2024
7 checks passed
@simw
Copy link
Owner

simw commented May 23, 2024

Thank you, looks great!

@simw
Copy link
Owner

simw commented May 23, 2024

Included in release 0.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants