maartenbreddels commented on a change in pull request #8271:
URL: https://github.com/apache/arrow/pull/8271#discussion_r500897047
##########
File path: python/pyarrow/_compute.pyx
##########
@@ -560,6 +560,29 @@ cdef class MatchSubstringOptions(FunctionOptions):
return self.match_substring_options.get()
+cdef class SplitOptions(FunctionOptions):
+ cdef:
+ unique_ptr[CSplitOptions] split_options
+
+ def __init__(self, max_splits, reverse):
+ self.split_options.reset(
+ new CSplitOptions(max_splits, reverse))
+
+ cdef const CFunctionOptions* get_options(self) except NULL:
+ return self.split_options.get()
+
+
+cdef class SplitPatternOptions(FunctionOptions):
+ cdef:
+ unique_ptr[CSplitPatternOptions] split_pattern_options
+
+ def __init__(self, pattern, max_splits, reverse):
Review comment:
when you have ```def __init__(self, pattern, *, max_splits=-1,
reverse=False):``` you'd expect to be able to write `result =
pc.split_pattern(arr, "---")` (without the pattern keyword). But that fails (`E
TypeError: wrapper() takes 1 positional argument but 2 were given`).
in code, this would make it pass:
```patch
diff --git a/python/pyarrow/compute.py b/python/pyarrow/compute.py
index 7b4ccd965..ee67bb39d 100644
--- a/python/pyarrow/compute.py
+++ b/python/pyarrow/compute.py
@@ -107,10 +107,10 @@ _option_classes = {
}
-def _handle_options(name, option_class, options, kwargs):
- if kwargs:
+def _handle_options(name, option_class, options, args, kwargs):
+ if kwargs or args:
if options is None:
- return option_class(**kwargs)
+ return option_class(*args, **kwargs)
raise TypeError(
"Function {!r} called with both an 'options' argument "
"and additional named arguments"
@@ -133,8 +133,8 @@ def _simple_unary_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)
+ def wrapper(arg, *args, options=None, memory_pool=None, **kwargs):
+ options = _handle_options(name, option_class, options, args,
kwargs)
return func.call([arg], options, memory_pool)
else:
def wrapper(arg, *, memory_pool=None):
```
Is this more clear?
----------------------------------------------------------------
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:
[email protected]