Skip to content

Commit ceb2d8d

Browse files
fix: forward write_options when write_parquet receives ParquetWriterOptions (#1761)
`write_parquet` takes `write_options`, documents it and declares it in the `@overload` for the `ParquetWriterOptions` form, but that branch calls `write_parquet_with_options(path, compression)` and drops it. The destination accepts the parameter, so everything in `DataFrameWriteOptions` (`partition_by`, `single_file_output`, `insert_operation`, `sort_by`) was silently ignored for that one spelling. Measured with the same `DataFrameWriteOptions(partition_by="part")`: write_parquet(path, ParquetWriterOptions(), write_options=wo) -> ['IDuOjvMa3pdEDotb_0.parquet'] not partitioned write_parquet_with_options(path, ParquetWriterOptions(), write_options=wo) -> ['part=a', 'part=b'] write_parquet(path, "zstd", write_options=wo) -> ['part=a', 'part=b'] No error and no warning: the files just land in the wrong layout. The branch arrived in ef62fa8 (#1169) while `write_options` came earlier in #857, so the new delegation path was written without carrying the existing parameter over. The same `if` refuses `compression_level` with an explicit `ValueError`, which shows that arguments incompatible with this branch get rejected on purpose; `write_options` was not rejected, only forgotten.
1 parent a2ddb55 commit ceb2d8d

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎python/datafusion/dataframe.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ def write_parquet(
16211621
if compression_level is not None:
16221622
msg = "compression_level should be None when using ParquetWriterOptions"
16231623
raise ValueError(msg)
1624-
self.write_parquet_with_options(path, compression)
1624+
self.write_parquet_with_options(path, compression, write_options)
16251625
return
16261626

16271627
if isinstance(compression, str):

‎python/tests/test_dataframe.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,25 @@ def test_write_parquet(df, tmp_path, path_to_str):
25382538
assert result == expected
25392539

25402540

2541+
def test_write_parquet_writer_options_keeps_write_options(ctx, tmp_path):
2542+
"""``write_parquet`` honours ``write_options`` alongside ``ParquetWriterOptions``.
2543+
2544+
The ``ParquetWriterOptions`` branch delegates to
2545+
:py:meth:`DataFrame.write_parquet_with_options`, which takes ``write_options``
2546+
too, so ``partition_by`` must still reach the writer.
2547+
"""
2548+
df = ctx.from_pydict({"part": ["a", "a", "b"], "v": [1, 2, 3]})
2549+
path = tmp_path / "partitioned"
2550+
2551+
df.write_parquet(
2552+
path,
2553+
ParquetWriterOptions(),
2554+
write_options=DataFrameWriteOptions(partition_by="part"),
2555+
)
2556+
2557+
assert sorted(p.name for p in path.iterdir()) == ["part=a", "part=b"]
2558+
2559+
25412560
@pytest.mark.parametrize(
25422561
("compression", "compression_level"),
25432562
[("gzip", 6), ("brotli", 7), ("zstd", 15)],

0 commit comments

Comments
 (0)