You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/10/14 20:55:37 UTC

[GitHub] [arrow] kszucs commented on a change in pull request #8457: ARROW-9164: [C++] Add embedded documentation to compute functions

kszucs commented on a change in pull request #8457:
URL: https://github.com/apache/arrow/pull/8457#discussion_r504966687



##########
File path: python/pyarrow/compute.py
##########
@@ -130,32 +146,38 @@ def _handle_options(name, option_class, options, kwargs):
     return options
 
 
-def _simple_unary_function(name):
-    func = get_function(name)
-    option_class = _option_classes.get(name)
-
-    if option_class is not None:
-        def wrapper(arg, *, options=None, memory_pool=None, **kwargs):
-            options = _handle_options(name, option_class, options, kwargs)
-            return func.call([arg], options, memory_pool)
-    else:
-        def wrapper(arg, *, memory_pool=None):
-            return func.call([arg], None, memory_pool)
-
-    return _decorate_compute_function(wrapper, name, func, option_class)
-
-
-def _simple_binary_function(name):
-    func = get_function(name)
-    option_class = _option_classes.get(name)
-
+_wrapper_template = dedent("""\
+    def make_wrapper(func, option_class):
+        def {func_name}({args_sig}, *, memory_pool=None):
+            return func.call([{args_sig}], None, memory_pool)
+        return {func_name}
+    """)
+
+_wrapper_options_template = dedent("""\
+    def make_wrapper(func, option_class):
+        def {func_name}({args_sig}, *, options=None, memory_pool=None,
+                        **kwargs):
+            options = _handle_options({func_name!r}, option_class, options,
+                                      kwargs)
+            return func.call([{args_sig}], options, memory_pool)
+        return {func_name}
+    """)
+
+
+def _wrap_function(name, func):
+    option_class = _get_options_class(func)
+    arg_names = _get_arg_names(func)
+    args_sig = ', '.join(arg_names)
+
+    # Generate templated wrapper, so that the signature matches
+    # the documented argument names.
+    ns = {}
     if option_class is not None:
-        def wrapper(left, right, *, options=None, memory_pool=None, **kwargs):
-            options = _handle_options(name, option_class, options, kwargs)
-            return func.call([left, right], options, memory_pool)
+        template = _wrapper_options_template
     else:
-        def wrapper(left, right, *, memory_pool=None):
-            return func.call([left, right], None, memory_pool)
+        template = _wrapper_template
+    exec(template.format(func_name=name, args_sig=args_sig), globals(), ns)

Review comment:
       Wouldn't it be better to set the `__signature__` property instead? 




----------------------------------------------------------------
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.

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