From a647ecac438c3ae1a5517651b6608fa1725b31ff Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 1 Jul 2021 08:55:41 -0400
Subject: [PATCH 1/3] ARROW-13236: [Python] Include options class name in repr
---
python/pyarrow/_compute.pyx | 4 +++-
python/pyarrow/includes/libarrow.pxd | 1 +
python/pyarrow/tests/test_compute.py | 2 +-
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx
index 63e6fffc782..0b89d112314 100644
--- a/python/pyarrow/_compute.pyx
+++ b/python/pyarrow/_compute.pyx
@@ -558,7 +558,9 @@ cdef class FunctionOptions(_Weakrefable):
return options
def __repr__(self):
- return frombytes(self.get_options().ToString())
+ type_name = self.__class__.__name__
+ string_repr = frombytes(self.get_options().ToString())
+ return 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..d7e854b637c 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
From 9b0a8bb9081494f1a118b97780678b45f9b6ee95 Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 1 Jul 2021 11:38:08 -0400
Subject: [PATCH 2/3] ARROW-13236: [Python] Also test exact repr
---
python/pyarrow/tests/test_compute.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py
index d7e854b637c..660b1acdb3d 100644
--- a/python/pyarrow/tests/test_compute.py
+++ b/python/pyarrow/tests/test_compute.py
@@ -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
From e124b4d76ba9dbb652539aa1f58974c5e26af200 Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 1 Jul 2021 12:41:30 -0400
Subject: [PATCH 3/3] ARROW-13236: [Python] Make repr look better
---
python/pyarrow/_compute.pyx | 5 +++--
python/pyarrow/tests/test_compute.py | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx
index 0b89d112314..02855ee78aa 100644
--- a/python/pyarrow/_compute.pyx
+++ b/python/pyarrow/_compute.pyx
@@ -559,8 +559,9 @@ cdef class FunctionOptions(_Weakrefable):
def __repr__(self):
type_name = self.__class__.__name__
- string_repr = frombytes(self.get_options().ToString())
- return type_name + string_repr
+ # 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/tests/test_compute.py b/python/pyarrow/tests/test_compute.py
index 660b1acdb3d..35b37d82f95 100644
--- a/python/pyarrow/tests/test_compute.py
+++ b/python/pyarrow/tests/test_compute.py
@@ -145,8 +145,8 @@ 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}"
+ assert repr(pc.IndexOptions(pa.scalar(1))) == "IndexOptions(value=int64:1)"
+ assert repr(pc.ArraySortOptions()) == "ArraySortOptions(order=Ascending)"
def test_list_functions():