Skip to content

Improve to_parquet "Schemas are inconsistent" error messages #8619

Closed

Description

@orf

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.

Activity

  1. changed the title [-]Improve Parquet "Schemas are inconsistent" error messages[/-] [+]Improve to_parquet "Schemas are inconsistent" error messages[/+] on Jan 25, 2022
  2. jsignell commented on Jan 25, 2022

    @jsignell
    Member

    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.

  3. added
    good first issue
    on Jan 25, 2022
  4. bryanwweber commented on Feb 2, 2022

    @bryanwweber
    Contributor

    @orf are you willing or able to create a pull request to address this? No pressure! Just trying to move this along if possible 😄

  5. Dranaxel commented on Feb 9, 2022

    @Dranaxel
    Contributor

    @orf Would you mind share your code ? Or at least a part so we can reproduce the error

  6. Dranaxel commented on Feb 11, 2022

    @Dranaxel
    Contributor

    Was looking to

    def to_parquet(

    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.

  7. rjzamora commented on Mar 23, 2022

    @rjzamora
    Member

    surely Dask knows what the differences are?

    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:

    def partition_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_info or {}).get("number", None)
            data = {name: [typ] for name, typ in zip(schema.names, schema.types)}
            data["partition-index"] = partition_id
            return partition.__class__(data)
        
        return ddf.map_partitions(
            _get_pyarrow_schema,
            meta=_get_pyarrow_schema(ddf._meta_nonempty),
        )
    
    print(partition_schemas(ddf).compute())

    Output:

           id    name       x       y      timestamp  partition-index
    0   int64  string  double  double  timestamp[ns]                0
    0   int64  string  double  double  timestamp[ns]                1
    0   int64    null  double  double  timestamp[ns]                2
    0  double  string  double  double  timestamp[ns]                3
    0   int64  string  double  double  timestamp[ns]                4
    ...
    

    Perhaps it would be useful to suggest using a utility like this in the original error message?

  8. self-assigned this
    on Apr 14, 2022
  9. hoangthienan95 commented on Apr 26, 2022

    @hoangthienan95

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dataframegood first issueparquet

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions