You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve to_parquet "Schemas are inconsistent" error messages #8619
We're trying to introduce Parquet into our team, and the largest blocker that we've seen is the dreaded "schemas are inconsistent" error message:
RuntimeError: Schemas are inconsistent, try using to_parquet(..., schema="infer"), or pass an explicit pyarrow schema. Such as to_parquet(..., schema={"column1": pa.string()})
This error message is super unhelpful: surely Dask knows what the differences are? If this comes from a job that produces tens of thousands of individual parquet files what it's really asking me to do is trawl through the individual partition schemas and work it out myself.
Could Dask expand this error message to provide some information about why the schemas are inconsistent? Is one partition's column a string whereas the other is a boolean? That would allow me to immediately pinpoint the issue. Something like:
RuntimeError: Schemas are inconsistent, try using `to_parquet(..., schema="infer")`, or pass an explicit pyarrow schema. Such as `to_parquet(..., schema={"column1": pa.string()})`. Conflicting columns:
- foo.bar: int (80), float (20)
- bar.baz: bool (1), str (99)
Including the number of partitions each conflicting column type would be useful. Obviously there are pathalogical cases where this message would be bad (thousands of conflicting columns), but for the general case I think it would really help.
changed the title [-]Improve Parquet "Schemas are inconsistent" error messages[/-][+]Improve to_parquet "Schemas are inconsistent" error messages[/+]on Jan 25, 2022
Thanks for raising this @orf! That seems like a really good idea to me. For the rare case where this would become very large, we can truncate part of the content.
This error occurs when pyarrow is used to aggregate parquet metadata before writing out the _metadata file. It may happen while the partition is being written, but usual occurs after. Pyarrow doesn't report any information about why the schema is mismatched, just that the schemas don't match.
We can certainly print out the schema for the old and new metadata in the error message (and probably should), but we cannot say which partition(s) caused the inconsistency. Perhaps we could add a simple partition_schemas utility to dask.dataframe.io.parquet.arrow to allow you to get a partition-wise view of the pyarrow schemas in your DataFrame collection? For example:
defpartition_schemas(ddf):
"""Return a Dask-DataFrame collection with each partition comprising a single row defining the pyarrow schema. """def_get_pyarrow_schema(partition, partition_info=None):
schema=pa.Schema.from_pandas(partition)
partition_id= (partition_infoor {}).get("number", None)
data= {name: [typ] forname, typinzip(schema.names, schema.types)}
data["partition-index"] =partition_idreturnpartition.__class__(data)
returnddf.map_partitions(
_get_pyarrow_schema,
meta=_get_pyarrow_schema(ddf._meta_nonempty),
)
print(partition_schemas(ddf).compute())
Just chiming in to say that this would be really helpful! A related error I get is reading multiple tsv files into Dask with path file_common_pattern_*.tsv, assuming that they have the same schema. However, one or more of them turn out to have different schemas that the rest and that cause inconsistent schema error downstream. I don't know which partition caused the error so have to check every partition/file's columns.
Activity
[-]Improve Parquet "Schemas are inconsistent" error messages[/-][+]Improve to_parquet "Schemas are inconsistent" error messages[/+]jsignell commentedon Jan 25, 2022
Thanks for raising this @orf! That seems like a really good idea to me. For the rare case where this would become very large, we can truncate part of the content.
bryanwweber commentedon Feb 2, 2022
@orf are you willing or able to create a pull request to address this? No pressure! Just trying to move this along if possible 😄
Dranaxel commentedon Feb 9, 2022
@orf Would you mind share your code ? Or at least a part so we can reproduce the error
Dranaxel commentedon Feb 11, 2022
Was looking to
dask/dask/dataframe/io/parquet/core.py
Line 530 in 20e9246
But I didn't find any interface which would allow me to raise any error. I would love some insight to work on this issue.
rjzamora commentedon Mar 23, 2022
This error occurs when pyarrow is used to aggregate parquet metadata before writing out the _metadata file. It may happen while the partition is being written, but usual occurs after. Pyarrow doesn't report any information about why the schema is mismatched, just that the schemas don't match.
We can certainly print out the schema for the old and new metadata in the error message (and probably should), but we cannot say which partition(s) caused the inconsistency. Perhaps we could add a simple
partition_schemasutility todask.dataframe.io.parquet.arrowto allow you to get a partition-wise view of the pyarrow schemas in your DataFrame collection? For example:Output:
Perhaps it would be useful to suggest using a utility like this in the original error message?
hoangthienan95 commentedon Apr 26, 2022
Just chiming in to say that this would be really helpful! A related error I get is reading multiple tsv files into Dask with path
file_common_pattern_*.tsv, assuming that they have the same schema. However, one or more of them turn out to have different schemas that the rest and that cause inconsistent schema error downstream. I don't know which partition caused the error so have to check every partition/file's columns.