From 1a331e1af0ec2e849ecac41084f65704d7dd4bb3 Mon Sep 17 00:00:00 2001 From: 1fanwang <1fannnw@gmail.com> Date: Fri, 4 Sep 2026 17:07:55 -0400 Subject: [PATCH 1/2] GH-51043: Reject null required PyArrow objects Generated-by: GitHub Copilot CLI (GPT-5.6 Sol) Signed-off-by: 1fanwang <1fannnw@gmail.com> --- python/pyarrow/_dataset.pyx | 5 ++++- python/pyarrow/_parquet.pyx | 5 +++-- python/pyarrow/array.pxi | 5 +++-- python/pyarrow/tests/parquet/test_metadata.py | 6 ++++++ python/pyarrow/tests/test_array.py | 4 ++++ python/pyarrow/tests/test_dataset.py | 6 ++++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/python/pyarrow/_dataset.pyx b/python/pyarrow/_dataset.pyx index d40614a61fc0..e06fc6caf6c9 100644 --- a/python/pyarrow/_dataset.pyx +++ b/python/pyarrow/_dataset.pyx @@ -1121,7 +1121,8 @@ cdef class FileSystemDataset(Dataset): cdef: CFileSystemDataset* filesystem_dataset - def __init__(self, fragments, Schema schema, FileFormat format, + def __init__(self, fragments, Schema schema not None, + FileFormat format not None, FileSystem filesystem=None, root_partition=None): cdef: FileFragment fragment=None @@ -1138,6 +1139,8 @@ cdef class FileSystemDataset(Dataset): ) for fragment in fragments: + if fragment is None: + raise TypeError("Fragment must not be None") c_fragments.push_back( static_pointer_cast[CFileFragment, CFragment]( fragment.unwrap())) diff --git a/python/pyarrow/_parquet.pyx b/python/pyarrow/_parquet.pyx index 932632a50410..435eed5e56c8 100644 --- a/python/pyarrow/_parquet.pyx +++ b/python/pyarrow/_parquet.pyx @@ -755,7 +755,8 @@ cdef class SortingColumn: self.nulls_first = nulls_first @classmethod - def from_ordering(cls, Schema schema, sort_keys, null_placement='at_end'): + def from_ordering(cls, Schema schema not None, sort_keys, + null_placement='at_end'): """ Create a tuple of SortingColumn objects from the same arguments as :class:`pyarrow.compute.SortOptions`. @@ -816,7 +817,7 @@ cdef class SortingColumn: return tuple(sorting_columns) @staticmethod - def to_ordering(Schema schema, sorting_columns): + def to_ordering(Schema schema not None, sorting_columns): """ Convert a tuple of SortingColumn objects to the same format as :class:`pyarrow.compute.SortOptions`. diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index 2b2130e992ed..c7c9127f7ecf 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -4293,8 +4293,9 @@ cdef class DictionaryArray(Array): return self._indices @staticmethod - def from_buffers(DataType type, int64_t length, buffers, Array dictionary, - int64_t null_count=-1, int64_t offset=0): + def from_buffers(DataType type not None, int64_t length, buffers, + Array dictionary, int64_t null_count=-1, + int64_t offset=0): """ Construct a DictionaryArray from buffers. diff --git a/python/pyarrow/tests/parquet/test_metadata.py b/python/pyarrow/tests/parquet/test_metadata.py index 9eee70b125e5..eafffd3436e0 100644 --- a/python/pyarrow/tests/parquet/test_metadata.py +++ b/python/pyarrow/tests/parquet/test_metadata.py @@ -351,6 +351,12 @@ def test_parquet_sorting_column(): with pytest.raises(ValueError): pq.SortingColumn.from_ordering(schema, (("a", "not a valid sort order"))) + with pytest.raises(TypeError, match="Argument 'schema' has incorrect type"): + pq.SortingColumn.from_ordering(None, ()) + + with pytest.raises(TypeError, match="Argument 'schema' has incorrect type"): + pq.SortingColumn.to_ordering(None, ()) + with pytest.raises(ValueError, match="inconsistent null placement"): sorting_cols = ( pq.SortingColumn(1, nulls_first=True), diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index a1e3616c9cea..bd8f23cc2105 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -928,6 +928,10 @@ def test_dictionary_from_buffers(offset): offset=offset) assert a[offset:] == b + with pytest.raises(TypeError, match="Argument 'type' has incorrect type"): + pa.DictionaryArray.from_buffers( + None, len(a), a.indices.buffers(), a.dictionary) + @pytest.mark.numpy def test_dictionary_from_numpy(): diff --git a/python/pyarrow/tests/test_dataset.py b/python/pyarrow/tests/test_dataset.py index 09d7cfb9d9dd..5376d182b63e 100644 --- a/python/pyarrow/tests/test_dataset.py +++ b/python/pyarrow/tests/test_dataset.py @@ -396,6 +396,12 @@ def test_filesystem_dataset(mockfs): # validation of required arguments with pytest.raises(TypeError, match="incorrect type"): ds.FileSystemDataset(fragments, file_format, schema) + with pytest.raises(TypeError, match="Fragment must not be None"): + ds.FileSystemDataset([None], schema=schema, format=file_format) + with pytest.raises(TypeError, match="Argument 'schema' has incorrect type"): + ds.FileSystemDataset(fragments, schema=None, format=file_format) + with pytest.raises(TypeError, match="Argument 'format' has incorrect type"): + ds.FileSystemDataset(fragments, schema=schema, format=None) # validation of root_partition with pytest.raises(TypeError, match="incorrect type"): ds.FileSystemDataset(fragments, schema=schema, From 6b429e85a11152d1955eb3292894d385c142e76c Mon Sep 17 00:00:00 2001 From: 1fanwang <1fannnw@gmail.com> Date: Sat, 5 Sep 2026 09:02:35 -0400 Subject: [PATCH 2/2] GH-51043: Reject null dictionary arrays Generated-by: GitHub Copilot CLI (GPT-5.6 Sol) Signed-off-by: 1fanwang <1fannnw@gmail.com> --- python/pyarrow/array.pxi | 2 +- python/pyarrow/tests/test_array.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index c7c9127f7ecf..d89b9d3e7e20 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -4294,7 +4294,7 @@ cdef class DictionaryArray(Array): @staticmethod def from_buffers(DataType type not None, int64_t length, buffers, - Array dictionary, int64_t null_count=-1, + Array dictionary not None, int64_t null_count=-1, int64_t offset=0): """ Construct a DictionaryArray from buffers. diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index bd8f23cc2105..9f47c5290a37 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -931,6 +931,9 @@ def test_dictionary_from_buffers(offset): with pytest.raises(TypeError, match="Argument 'type' has incorrect type"): pa.DictionaryArray.from_buffers( None, len(a), a.indices.buffers(), a.dictionary) + with pytest.raises(TypeError, match="Argument 'dictionary' has incorrect type"): + pa.DictionaryArray.from_buffers( + a.type, len(a), a.indices.buffers(), None) @pytest.mark.numpy