Skip to content

Commit

Permalink
apacheGH-39440: [Python] Calling pyarrow.dataset.ParquetFileFormat.ma…
Browse files Browse the repository at this point in the history
…ke_write_options as a class method results in a segfault (apache#40976)

### Rationale for this change

Calling `make_write_options()` method as class instead of instance method results in segfault.

### What changes are included in this PR?

Adds a type check on `self` and raises an error if not `ParquetFileFormat`.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* GitHub Issue: apache#39440

Lead-authored-by: AlenkaF <frim.alenka@gmail.com>
Co-authored-by: Alenka Frim <AlenkaF@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Signed-off-by: AlenkaF <frim.alenka@gmail.com>
  • Loading branch information
2 people authored and tolleybot committed May 2, 2024
1 parent 339776d commit 5fb390c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/pyarrow/_dataset_parquet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ cdef class ParquetFileFormat(FileFormat):
-------
pyarrow.dataset.FileWriteOptions
"""
# Safeguard from calling make_write_options as a static class method
if not isinstance(self, ParquetFileFormat):
raise TypeError("make_write_options() should be called on "
"an instance of ParquetFileFormat")
opts = FileFormat.make_write_options(self)
(<ParquetFileWriteOptions> opts).update(**kwargs)
return opts
Expand Down
13 changes: 13 additions & 0 deletions python/pyarrow/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5630,3 +5630,16 @@ def test_checksum_write_dataset_read_dataset_to_table(tempdir):
corrupted_dir_path,
format=pq_read_format_crc
).to_table()


def test_make_write_options_error():
# GH-39440
msg = ("make_write_options\\(\\) should be called on an "
"instance of ParquetFileFormat")
with pytest.raises(TypeError, match=msg):
pa.dataset.ParquetFileFormat.make_write_options(43)

pformat = pa.dataset.ParquetFileFormat()
msg = "make_write_options\\(\\) takes exactly 0 positional arguments"
with pytest.raises(TypeError, match=msg):
pformat.make_write_options(43)

0 comments on commit 5fb390c

Please sign in to comment.