jorisvandenbossche commented on a change in pull request #10511:
URL: https://github.com/apache/arrow/pull/10511#discussion_r662253067



##########
File path: python/pyarrow/_compute.pyx
##########
@@ -526,9 +526,70 @@ def call_function(name, args, options=None, 
memory_pool=None):
 
 
 cdef class FunctionOptions(_Weakrefable):
+    __slots__ = ()  # avoid mistakingly creating attributes
 
     cdef const CFunctionOptions* get_options(self) except NULL:
-        raise NotImplementedError("Unimplemented base options")
+        return self.wrapped.get()
+
+    cdef void init(self, unique_ptr[CFunctionOptions] options):
+        self.wrapped = move(options)
+
+    def serialize(self):
+        cdef:
+            CResult[shared_ptr[CBuffer]] res = self.get_options().Serialize()
+            shared_ptr[CBuffer] c_buf = GetResultValue(res)
+        return pyarrow_wrap_buffer(c_buf)
+
+    @staticmethod
+    def deserialize(buf):
+        cdef:
+            shared_ptr[CBuffer] c_buf = pyarrow_unwrap_buffer(buf)
+            CResult[unique_ptr[CFunctionOptions]] maybe_options = \
+                DeserializeFunctionOptions(deref(c_buf))
+            unique_ptr[CFunctionOptions] c_options
+        c_options = move(GetResultValue(move(maybe_options)))
+        type_name = frombytes(c_options.get().options_type().type_name())
+        mapping = {
+            "array_sort": ArraySortOptions,
+            "cast": CastOptions,
+            "dictionary_encode": DictionaryEncodeOptions,
+            "element_wise_aggregate": ElementWiseAggregateOptions,
+            "extract_regex": ExtractRegexOptions,
+            "filter": FilterOptions,
+            "index": IndexOptions,
+            "join": JoinOptions,
+            "match_substring": MatchSubstringOptions,
+            "mode": ModeOptions,
+            "pad": PadOptions,
+            "partition_nth": PartitionNthOptions,
+            "project": ProjectOptions,
+            "quantile": QuantileOptions,
+            "replace_slice": ReplaceSliceOptions,
+            "replace_substring": ReplaceSubstringOptions,
+            "set_lookup": SetLookupOptions,
+            "scalar_aggregate": ScalarAggregateOptions,
+            "slice": SliceOptions,
+            "sort": SortOptions,
+            "split": SplitOptions,
+            "split_pattern": SplitPatternOptions,
+            "strptime": StrptimeOptions,
+            "t_digest": TDigestOptions,
+            "take": TakeOptions,
+            "trim": TrimOptions,
+            "variance": VarianceOptions,
+        }
+        if type_name not in mapping:
+            raise ValueError(f"Cannot deserialize '{type_name}'")
+        klass = mapping[type_name]
+        options = klass.__new__(klass)
+        (<FunctionOptions> options).init(move(c_options))
+        return options
+
+    def __repr__(self):
+        return frombytes(self.get_options().ToString())

Review comment:
       We probably still want to include the name of the options in the output 
(now it's only the arguments). 
   
   ```
   In [9]: pc.TrimOptions("a")
   Out[9]: {characters="a"}
   ```
   
   Opened https://issues.apache.org/jira/browse/ARROW-13236 for this for the 
Python side (or is that something we also want to add on the C++ side?)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to