Skip to content
Closed
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
5 changes: 4 additions & 1 deletion python/pyarrow/_compute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
1 change: 1 addition & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion python/pyarrow/tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ 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__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test the actual repr for one or two classes somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some assertions at the bottom of the test.

buf = option.serialize()
deserialized = pc.FunctionOptions.deserialize(buf)
assert option == deserialized
assert repr(option) == repr(deserialized)
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
Expand Down