New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-9164: [C++] Add embedded documentation to compute functions #8457
Conversation
2c75b60
to
8010c4e
Compare
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to set the __signature__
property instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Altogether this looks like a great improvement in the usability of the compute module, thanks for doing this!
option_class = _get_options_class(func) | ||
arg_names = _get_arg_names(func) | ||
args_sig = ', '.join(arg_names) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if option_class is None: | |
def wrapper(*args, *, memory_pool=None): | |
return func.call(args, None, memory_pool) | |
wrapped_template = 'lambda {}, *, memory_pool=None: ()' | |
else: | |
def wrapper(*args, *, options=None, memory_pool=None, **kwargs): | |
options = _handle_options(name, option_class, options, kwargs) | |
return func.call(args, options, memory_pool) | |
wrapped_template = 'lambda {}, *, options=None, memory_pool=None, **kwargs: ()' | |
wrapper.__name__ = name | |
wrapper.__qualname__ = name | |
wrapper.__wrapped__ = eval(wrapped_template.format(args_sig)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I didn't know that __wrapped__
was taken up by inspect.signature
. Interesting. I'd rather examine this later though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Also the python docstrings ;)
I mostly did a review of the docstrings' content now (and not yet the generation machinery)
FunctionDoc list_parent_indices_doc( | ||
"Compute parent indices of nested list values", | ||
("`lists` must have a list-like type.\n" | ||
"For each value in each list of `lists`, the top-level list index\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but I think that for conceptually more complex functions (like this one, for me), it might be useful to include a small example. But that might get verbose to write in this form ..
For example, for this case: [[1, 2], [3, 4, 5], [6]]
returns [0, 0, 1, 1, 1, 2]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's not obvious how to make this too unwiedly to write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going further down the docstring rabbithole: we could introduce a doctest-like class (of which a FunctionDoc contains a vector), which could just be a set of lambdas which generate a set of inputs, options, and maybe the expected output. These can then be rendered lazily in python
8010c4e
to
2b0e393
Compare
@nealrichardson @kou This may help for R and Ruby. |
Wow! Great! x = table
x.A(y, z)
x = record_batch
x.A(y, z) |
Will rebase and merge. |
Also re-use the embedded documentations in Python to generate nicer signatures and docstrings.
Expose CountOptions. Improve introspectability of option classes.
2b0e393
to
61fc098
Compare
Travis-CI build: https://travis-ci.org/github/pitrou/arrow/builds/737045923 CI failures are unrelated. |
Also re-use the embedded documentations in Python to generate nicer signatures and docstrings. Closes #8457 from pitrou/ARROW-9164-compute-func-docs Authored-by: Antoine Pitrou <antoine@python.org> Signed-off-by: Antoine Pitrou <antoine@python.org>
Also re-use the embedded documentations in Python to generate nicer signatures and docstrings. Closes apache#8457 from pitrou/ARROW-9164-compute-func-docs Authored-by: Antoine Pitrou <antoine@python.org> Signed-off-by: Antoine Pitrou <antoine@python.org>
Also re-use the embedded documentations in Python to generate nicer signatures and docstrings. Closes apache#8457 from pitrou/ARROW-9164-compute-func-docs Authored-by: Antoine Pitrou <antoine@python.org> Signed-off-by: Antoine Pitrou <antoine@python.org>
Also re-use the embedded documentations in Python to generate nicer signatures and docstrings.