(wrapper, exposed_name, func, options_class)
| 127 | |
| 128 | |
| 129 | def _decorate_compute_function(wrapper, exposed_name, func, options_class): |
| 130 | # Decorate the given compute function wrapper with useful metadata |
| 131 | # and documentation. |
| 132 | cpp_doc = func._doc |
| 133 | |
| 134 | wrapper.__arrow_compute_function__ = dict( |
| 135 | name=func.name, |
| 136 | arity=func.arity, |
| 137 | options_class=cpp_doc.options_class, |
| 138 | options_required=cpp_doc.options_required) |
| 139 | wrapper.__name__ = exposed_name |
| 140 | wrapper.__qualname__ = exposed_name |
| 141 | |
| 142 | doc_pieces = [] |
| 143 | |
| 144 | # 1. One-line summary |
| 145 | summary = cpp_doc.summary |
| 146 | if not summary: |
| 147 | arg_str = "arguments" if func.arity > 1 else "argument" |
| 148 | summary = f"Call compute function {func.name!r} with the given {arg_str}" |
| 149 | |
| 150 | doc_pieces.append(f"{summary}.\n\n") |
| 151 | |
| 152 | # 2. Multi-line description |
| 153 | description = cpp_doc.description |
| 154 | if description: |
| 155 | doc_pieces.append(f"{description}\n\n") |
| 156 | |
| 157 | doc_addition = _compute_docstrings.function_doc_additions.get(func.name) |
| 158 | |
| 159 | # 3. Parameter description |
| 160 | doc_pieces.append(dedent("""\ |
| 161 | Parameters |
| 162 | ---------- |
| 163 | """)) |
| 164 | |
| 165 | # 3a. Compute function parameters |
| 166 | arg_names = _get_arg_names(func) |
| 167 | for arg_name in arg_names: |
| 168 | if func.kind in ('vector', 'scalar_aggregate'): |
| 169 | arg_type = 'Array-like' |
| 170 | else: |
| 171 | arg_type = 'Array-like or scalar-like' |
| 172 | doc_pieces.append(f"{arg_name} : {arg_type}\n") |
| 173 | doc_pieces.append(" Argument to compute function.\n") |
| 174 | |
| 175 | # 3b. Compute function option values |
| 176 | if options_class is not None: |
| 177 | options_class_doc = _scrape_options_class_doc(options_class) |
| 178 | if options_class_doc: |
| 179 | for p in options_class_doc.params: |
| 180 | doc_pieces.append(f"{p.name} : {p.type}\n") |
| 181 | for s in p.desc: |
| 182 | doc_pieces.append(f" {s}\n") |
| 183 | else: |
| 184 | warnings.warn(f"Options class {options_class.__name__} " |
| 185 | f"does not have a docstring", RuntimeWarning) |
| 186 | options_sig = inspect.signature(options_class) |
no test coverage detected