diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx index ee3ebd6d0e9..789e710875e 100644 --- a/python/pyarrow/_compute.pyx +++ b/python/pyarrow/_compute.pyx @@ -2686,7 +2686,7 @@ cdef class Expression(_Weakrefable): cdef inline CExpression unwrap(self): return self.expr - def equals(self, Expression other): + def equals(self, Expression other not None): """ Parameters ---------- diff --git a/python/pyarrow/_dataset.pyx b/python/pyarrow/_dataset.pyx index 8889090801c..fb4d0236d5c 100644 --- a/python/pyarrow/_dataset.pyx +++ b/python/pyarrow/_dataset.pyx @@ -4052,7 +4052,7 @@ cdef class Scanner(_Weakrefable): return reader -def get_partition_keys(Expression partition_expression): +def get_partition_keys(Expression partition_expression not None): """ Extract partition keys (equality constraints between a field and a scalar) from an expression as a dict mapping the field's name to its value. diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py index 691d2ec98f3..0e0260808d6 100644 --- a/python/pyarrow/tests/test_compute.py +++ b/python/pyarrow/tests/test_compute.py @@ -4371,6 +4371,9 @@ def test_expression_construction(): with pytest.raises(TypeError): field.isin(1) + with pytest.raises(TypeError, match="Argument 'other' has incorrect type"): + field.equals(None) + with pytest.raises(pa.ArrowInvalid): field != object() diff --git a/python/pyarrow/tests/test_dataset.py b/python/pyarrow/tests/test_dataset.py index 3b575e24d5e..925786e5c4c 100644 --- a/python/pyarrow/tests/test_dataset.py +++ b/python/pyarrow/tests/test_dataset.py @@ -946,6 +946,9 @@ def test_partition_keys(): null = ds.field('a').is_null() assert ds.get_partition_keys(null) == {'a': None} + with pytest.raises(TypeError, match="Argument 'partition_expression'"): + ds.get_partition_keys(None) + @pytest.mark.parquet def test_parquet_read_options():