Skip to content

Commit 074d45f

Browse files
AlenkaFpitrou
andauthored
GH-39440: [Python] Calling pyarrow.dataset.ParquetFileFormat.make_write_options as a class method results in a segfault (#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: #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>
1 parent 139afe5 commit 074d45f

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

python/pyarrow/_dataset_parquet.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ cdef class ParquetFileFormat(FileFormat):
198198
-------
199199
pyarrow.dataset.FileWriteOptions
200200
"""
201+
# Safeguard from calling make_write_options as a static class method
202+
if not isinstance(self, ParquetFileFormat):
203+
raise TypeError("make_write_options() should be called on "
204+
"an instance of ParquetFileFormat")
201205
opts = FileFormat.make_write_options(self)
202206
(<ParquetFileWriteOptions> opts).update(**kwargs)
203207
return opts

python/pyarrow/tests/test_dataset.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,3 +5630,16 @@ def test_checksum_write_dataset_read_dataset_to_table(tempdir):
56305630
corrupted_dir_path,
56315631
format=pq_read_format_crc
56325632
).to_table()
5633+
5634+
5635+
def test_make_write_options_error():
5636+
# GH-39440
5637+
msg = ("make_write_options\\(\\) should be called on an "
5638+
"instance of ParquetFileFormat")
5639+
with pytest.raises(TypeError, match=msg):
5640+
pa.dataset.ParquetFileFormat.make_write_options(43)
5641+
5642+
pformat = pa.dataset.ParquetFileFormat()
5643+
msg = "make_write_options\\(\\) takes exactly 0 positional arguments"
5644+
with pytest.raises(TypeError, match=msg):
5645+
pformat.make_write_options(43)

0 commit comments

Comments
 (0)