Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/pyarrow/_compute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ class CountOptions(_CountOptions):


cdef class _IndexOptions(FunctionOptions):
def _set_options(self, scalar):
def _set_options(self, Scalar scalar not None):
self.wrapped.reset(new CIndexOptions(pyarrow_unwrap_scalar(scalar)))


Expand All @@ -1682,7 +1682,7 @@ class IndexOptions(_IndexOptions):
The value to search for.
"""

def __init__(self, value):
def __init__(self, Scalar value not None):
self._set_options(value)


Expand Down
2 changes: 2 additions & 0 deletions python/pyarrow/_dataset_parquet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ cdef class ParquetReadOptions(_Weakrefable):
@binary_type.setter
def binary_type(self, ty):
if ty is not None:
if not isinstance(ty, DataType):
raise TypeError(f"DataType expected, got {type(ty)!r}")
self._binary_type = pyarrow_unwrap_data_type(ty).get().id()
else:
self._binary_type = _Type_BINARY
Expand Down
4 changes: 3 additions & 1 deletion python/pyarrow/_parquet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from cython.operator cimport dereference as deref
from pyarrow.includes.common cimport *
from pyarrow.includes.libarrow cimport *
from pyarrow.includes.libarrow_python cimport *
from pyarrow.lib cimport (_Weakrefable, Buffer, Schema,
from pyarrow.lib cimport (_Weakrefable, Buffer, DataType, Schema,
check_status,
MemoryPool, maybe_unbox_memory_pool,
Table, KeyValueMetadata,
Expand Down Expand Up @@ -1656,6 +1656,8 @@ cdef class ParquetReader(_Weakrefable):
properties.set_page_checksum_verification(page_checksum_verification)

if binary_type is not None:
if not isinstance(binary_type, DataType):
raise TypeError(f"DataType expected, got {type(binary_type)!r}")
c_binary_type = pyarrow_unwrap_data_type(binary_type)
arrow_props.set_binary_type(c_binary_type.get().id())

Expand Down
5 changes: 3 additions & 2 deletions python/pyarrow/_substrait.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class SubstraitSchema:
return py_substrait.proto.ExtendedExpression.FromString(self.expression)


def serialize_schema(schema):
def serialize_schema(Schema schema not None):
"""
Serialize a schema into a SubstraitSchema object.

Expand Down Expand Up @@ -293,7 +293,8 @@ def deserialize_schema(buf):
return pyarrow_wrap_schema(c_schema)


def serialize_expressions(exprs, names, schema, *, allow_arrow_extensions=False):
def serialize_expressions(exprs, names, Schema schema not None, *,
allow_arrow_extensions=False):
"""
Serialize a collection of expressions into Substrait

Expand Down
8 changes: 4 additions & 4 deletions python/pyarrow/tensor.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ shape: {self.shape}"""
return pyarrow_wrap_sparse_coo_tensor(csparse_tensor)

@staticmethod
def from_tensor(obj):
def from_tensor(Tensor obj not None):
"""
Convert arrow::Tensor to arrow::SparseCOOTensor.

Expand Down Expand Up @@ -862,7 +862,7 @@ shape: {self.shape}"""
return pyarrow_wrap_sparse_csr_matrix(csparse_tensor)

@staticmethod
def from_tensor(obj):
def from_tensor(Tensor obj not None):
"""
Convert arrow::Tensor to arrow::SparseCSRMatrix.

Expand Down Expand Up @@ -1133,7 +1133,7 @@ shape: {self.shape}"""
return pyarrow_wrap_sparse_csc_matrix(csparse_tensor)

@staticmethod
def from_tensor(obj):
def from_tensor(Tensor obj not None):
"""
Convert arrow::Tensor to arrow::SparseCSCMatrix

Expand Down Expand Up @@ -1406,7 +1406,7 @@ shape: {self.shape}"""
return pyarrow_wrap_sparse_csf_tensor(csparse_tensor)

@staticmethod
def from_tensor(obj):
def from_tensor(Tensor obj not None):
"""
Convert arrow::Tensor to arrow::SparseCSFTensor

Expand Down
9 changes: 9 additions & 0 deletions python/pyarrow/tests/parquet/test_parquet_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
pytestmark = pytest.mark.parquet


def test_parquet_file_rejects_invalid_binary_type():
sink = io.BytesIO()
pq.write_table(pa.table({"value": [b"data"]}), sink)
sink.seek(0)

with pytest.raises(TypeError, match="DataType expected"):
pq.ParquetFile(sink, binary_type=0)


@pytest.mark.pandas
def test_pass_separate_metadata():
# ARROW-471
Expand Down
3 changes: 3 additions & 0 deletions python/pyarrow/tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ def test_option_class_equality(request):
assert repr(pc.ArraySortOptions()) == \
"ArraySortOptions(order=Ascending, null_placement=AtEnd)"

with pytest.raises(TypeError, match="Argument 'value' has incorrect type"):
pc.IndexOptions(0)


def test_list_functions():
assert len(pc.list_functions()) > 10
Expand Down
3 changes: 3 additions & 0 deletions python/pyarrow/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,9 @@ def test_parquet_read_options():
assert opts5.list_type is pa.LargeListType
assert opts5 != opts1

with pytest.raises(TypeError, match="DataType expected"):
ds.ParquetReadOptions(binary_type=0)


@pytest.mark.parquet
def test_parquet_file_format_read_options():
Expand Down
11 changes: 11 additions & 0 deletions python/pyarrow/tests/test_sparse_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def test_sparse_tensor_attrs(sparse_tensor_type):
assert wr() is None


@pytest.mark.parametrize('sparse_tensor_type', [
pa.SparseCSRMatrix,
pa.SparseCSCMatrix,
pa.SparseCOOTensor,
pa.SparseCSFTensor,
])
def test_sparse_tensor_from_tensor_rejects_invalid_type(sparse_tensor_type):
with pytest.raises(TypeError, match="Argument 'obj' has incorrect type"):
sparse_tensor_type.from_tensor(0)


def test_sparse_coo_tensor_base_object():
expected_data = np.array([[8, 2, 5, 3, 4, 6]]).T
expected_coords = np.array([
Expand Down
6 changes: 6 additions & 0 deletions python/pyarrow/tests/test_substrait.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,12 @@ def test_serializing_schema():
returned = pa.substrait.deserialize_expressions(arrow_substrait_schema.expression)
assert returned.schema == expected_schema

with pytest.raises(TypeError, match="Argument 'schema' has incorrect type"):
pa.substrait.serialize_schema(0)

with pytest.raises(TypeError, match="Argument 'schema' has incorrect type"):
pa.substrait.serialize_expressions([], [], 0)


def test_bound_expression_from_Message():
class FakeMessage:
Expand Down