diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx index 63e6fffc782..02855ee78aa 100644 --- a/python/pyarrow/_compute.pyx +++ b/python/pyarrow/_compute.pyx @@ -558,7 +558,10 @@ cdef class FunctionOptions(_Weakrefable): return options def __repr__(self): - return frombytes(self.get_options().ToString()) + type_name = self.__class__.__name__ + # Remove {} so we can use our own braces + string_repr = frombytes(self.get_options().ToString())[1:-1] + return f"{type_name}({string_repr})" def __eq__(self, FunctionOptions other): return self.get_options().Equals(deref(other.get_options())) diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd index 07983b79f40..5057eadbb43 100644 --- a/python/pyarrow/includes/libarrow.pxd +++ b/python/pyarrow/includes/libarrow.pxd @@ -1756,6 +1756,7 @@ cdef extern from "arrow/compute/api.h" namespace "arrow::compute" nogil: cdef cppclass CFunctionOptions" arrow::compute::FunctionOptions": const CFunctionOptionsType* options_type() const + const char* type_name() const c_bool Equals(const CFunctionOptions& other) c_string ToString() CResult[shared_ptr[CBuffer]] Serialize() const diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py index 6370a5d94e2..35b37d82f95 100644 --- a/python/pyarrow/tests/test_compute.py +++ b/python/pyarrow/tests/test_compute.py @@ -137,7 +137,7 @@ def test_option_class_equality(): pytest.fail(f"Options class is not tested: {cls}") for option in options: assert option == option - assert repr(option) + assert repr(option).startswith(option.__class__.__name__) buf = option.serialize() deserialized = pc.FunctionOptions.deserialize(buf) assert option == deserialized @@ -145,6 +145,9 @@ def test_option_class_equality(): for option1, option2 in zip(options, options[1:]): assert option1 != option2 + assert repr(pc.IndexOptions(pa.scalar(1))) == "IndexOptions(value=int64:1)" + assert repr(pc.ArraySortOptions()) == "ArraySortOptions(order=Ascending)" + def test_list_functions(): assert len(pc.list_functions()) > 10