Repository navigation
Enfore consistent schema in to_parquet pyarrow - #9131
Merged
Merged
Conversation
Previously each partition written in `to_parquet` with
`engine="pyarrow"` had their schema inferred based solely on data within
that partition alone. This leads to a few common problems:
- Mismatched inferred schemas between partitions aren't caught, leading
to issues in downstream consumers. Most readers assume a uniform
parquet schema across files, which wasn't enforced by default by the
pyarrow engine.
- Inference was supported with `schema="infer"`, but:
- It was expensive, requiring computing at least one partition
(sometimes more) to get a sample of any `object` dtypes.
- Inference here for non-string object dtypes is silently incorrect,
users should really be explicit here when trying to write more
complicated schemas containing structured fields.
- Inference was off by default
- When writing a `_metadata` file, differences in per-file schemas would
result in opaque errors when merging the metadata before writing. This
error is deep in the `arrow` codebase, and doesn't provide enough
information for the user to debug where the schema mismatch occured.
Turning on schema enforcement by default lets us generate a better
error message,
This PR changes the `schema` parameter in the following way:
- `schema="infer"` is the default
- schema inference assumes object fields are strings (common), and makes
no attempt at more complicated inference. Users with more complicated
schemas should specify those explicitly. This means that schema
inference is now cheap.
- A better error message is generated for mismatched partition dtypes in
`to_parquet` for the `pyarrow` engine. The fastparquet engine already
does this.
Member
Author
|
cc @rjzamora, @ian-r-rose |
ian-r-rose
self-requested a review
May 26, 2022 16:53
Member
Author
|
Test failures are unrelated. |
rjzamora
self-requested a review
May 26, 2022 19:18
rjzamora
approved these changes
May 26, 2022
rjzamora
left a comment
Member
There was a problem hiding this comment.
Thanks for working through this @jcrist !
I definitely +1 on this change. The previous schema=“infer” option was a bit of a misnomer (schema=“sample” would have been more accurate), and it didn’t do much (anything?) to prevent schema-mismatch errors. I think it makes sense to use the non-empty metadata by default, and simply do a better job of pointing the user towards a “proper” schema= argument when this goes wrong.
ian-r-rose
reviewed
May 26, 2022
ian-r-rose
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @jcrist, this looks good to me. Any time we can remove eager computation, I'm in favor.
ian-r-rose
approved these changes
May 26, 2022
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously each partition written in
to_parquetwithengine="pyarrow"had their schema inferred based solely on data withinthat partition alone. This leads to a few common problems:
to issues in downstream consumers. Most readers assume a uniform
parquet schema across files, which wasn't enforced by default by the
pyarrow engine.
schema="infer", but:(sometimes more) to get a sample of any
objectdtypes.users should really be explicit here when trying to write more
complicated schemas containing structured fields.
_metadatafile, differences in per-file schemas wouldresult in opaque errors when merging the metadata before writing. This
error is deep in the
arrowcodebase, and doesn't provide enoughinformation for the user to debug where the schema mismatch occured.
Turning on schema enforcement by default lets us generate a better
error message,
This PR changes the
schemaparameter in the following way:schema="infer"is the defaultno attempt at more complicated inference. Users with more complicated
schemas should specify those explicitly. This means that schema
inference is now cheap.
to_parquetfor thepyarrowengine. The fastparquet engine alreadydoes this.
Fixes #8619, Fixes #8832