diff --git a/python/pyarrow/_dataset.pyx b/python/pyarrow/_dataset.pyx index d40614a61fc..e06fc6caf6c 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 932632a5041..435eed5e56c 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 2b2130e992e..d89b9d3e7e2 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 not None, 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 9eee70b125e..eafffd3436e 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 a1e3616c9ce..9f47c5290a3 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -928,6 +928,13 @@ 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) + 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 def test_dictionary_from_numpy(): diff --git a/python/pyarrow/tests/test_dataset.py b/python/pyarrow/tests/test_dataset.py index 09d7cfb9d9d..5376d182b63 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,