diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx index b7b4bed2ccf3f..0037fe4135702 100644 --- a/python/pyarrow/_compute.pyx +++ b/python/pyarrow/_compute.pyx @@ -416,7 +416,8 @@ cdef class MetaFunction(Function): cdef _pack_compute_args(object values, vector[CDatum]* out): for val in values: - if isinstance(val, (list, np.ndarray)): + if isinstance(val, (list, np.ndarray)) or \ + hasattr(val, '__arrow_array__'): val = lib.asarray(val) if isinstance(val, Array): diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py index cacc40decea85..b310b0b32558a 100644 --- a/python/pyarrow/tests/test_compute.py +++ b/python/pyarrow/tests/test_compute.py @@ -293,6 +293,15 @@ def test_input_type_conversion(): "foo").to_pylist() == [True, False, None] +def test_input_array_conversion(): + class convertible: + def __arrow_array__(self, type=None): + return pa.array(range(5), type) + + assert pc.sum(np.arange(5)).as_py() == 10 + assert pc.sum(convertible()).as_py() == 10 + + @pytest.mark.parametrize('arrow_type', numerical_arrow_types) def test_sum_array(arrow_type): arr = pa.array([1, 2, 3, 4], type=arrow_type)