Skip to content

Conversation

kosiew
Copy link
Contributor

@kosiew kosiew commented Jun 24, 2025

Which issue does this PR close?

Rationale for this change

This change enhances the flexibility of the Parquet writing process by allowing users to specify both compression type and compression level through a unified ParquetWriterOptions object. It also prevents conflicting configurations when options are explicitly passed.

What changes are included in this PR?

  • Added compression_level parameter to ParquetWriterOptions.
  • Enhanced DataFrame.write_parquet() to accept a ParquetWriterOptions object.
  • Added logic to prevent conflicting use of compression_level when using a full options object.
  • Introduced two new tests:
    • test_write_parquet_options: Verifies functionality with custom compression and level.
    • test_write_parquet_options_error: Ensures proper error is raised for misconfiguration.

Are these changes tested?

Yes, two new tests have been added:

  • test_write_parquet_options: Confirms Parquet output matches expected data.
  • test_write_parquet_options_error: Validates error handling when conflicting options are provided.

Are there any user-facing changes?

Yes:

  • Users can now pass a ParquetWriterOptions object directly to DataFrame.write_parquet(), allowing more granular control.
  • A ValueError will be raised if compression_level is used with an already configured options object.

Comment on lines 877 to 883
def write_parquet(
self,
path: str | pathlib.Path,
compression: Union[str, Compression] = Compression.ZSTD,
compression: Union[str, Compression, ParquetWriterOptions] = Compression.ZSTD,
compression_level: int | None = None,
) -> None:
"""Execute the :py:class:`DataFrame` and write the results to a Parquet file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is nice. I think it would be a little better for type hinting in IDEs if we overload the method signatures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the overload.

@timsaucer timsaucer merged commit ef62fa8 into apache:main Jun 25, 2025
17 checks passed
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.

Unify write_parquet signatures

2 participants