Skip to content

Add compression_level support to ParquetWriterOptions and enhance write_parquet to accept full options object #1169

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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
Contributor

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.

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