[JNI][DOC] Proposal for standardized code examples in Java docstrings
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.1k
- Avg merge
- 3d 6m
- Merged PRs (30d)
- 278
Description
## Report needed documentation
Developer friendliness (for humans and AIs alike) is important for the cuDF Java APIs, since (among other reasons) these APIs are required to implement Spark [RAPIDS Accelerated UDFs](https://nvidia.github.io/spark-rapids/docs/additional-functionality/rapids-udfs.html). Many of the current APIs lack good documentation and usage examples.
### Proposal
As a starting point, I'm proposing a standardized code block included in each docstring, inspired by [Thrust docs](https://nvidia.github.io/cccl/thrust/api/group__transformations_1gabbda6380c902223d777cc72d3b1b9d1a.html#transform-exec-first-last-result-op), containing the following:
- **input**: values and dtypes of each argument in a comment
- **method call**: line of code showing method invocation
- **output**: results values and dtypes in a comment
E.g., for a Column method.
**Before:**
```java
/**
* Do a segmented reduce where the offsets column indicates which groups in this to combine. The
* output type is the same as the input type.
* @param offsets an INT32 column with no nulls.
* @param aggregation the aggregation to do
* @return the result.
*/
public ColumnVector segmentedReduce(ColumnView offsets, SegmentedReductionAggregation aggregation) {
```
**After:**
```java
/**
* Do a segmented reduce where the offsets column indicates which groups in this to combine. The
* output type is the same as the input type.
*
*
Example:
*
{@code
* // col = [1, 2, 3, 4, 5], DType = INT32
* // offsets = [0, 2, 5], DType = INT32
* ColumnVector result = col.segmentedReduce(offsets, SegmentedReductionAggregation.sum());
* // result = [3, 12], DType = INT32
* }
*
* @param offsets an INT32 column with no nulls.
* @param aggregation the aggregation to do
* @return the result.
*/
public ColumnVector segmentedReduce(ColumnView offsets, SegmentedReductionAggregation aggregation) {
```
E.g., for a Table method:
**Before:**
```java
/**
* Gathers the rows of this table according to `gatherMap` such that row "i"
* in the resulting table's columns will contain row "gatherMap[i]" from this table.
* @param gatherMap the map of indexes.
* @return the resulting Table.
*/
public Table gather(ColumnView gatherMap) {
```
**After:**
```java
/**
* Gathers the rows of this table according to `gatherMap` such that row "i"
* in the resulting table's columns will contain row "gatherMap[i]" from this table.
*
*
Example:
*
{@code
* // table:
* // col0 = ["a", "b", "c", "d"], DType = STRING
* // col1 = [10, 20, 30, 40], DType = INT32
* // gatherMap = [3, 1, 2], DType = INT32
* Table result = table.gather(gatherMap);
* // result:
* // col0 = ["d", "b", "c"], DType = STRING
* // col1 = [40, 20, 30], DType = INT32
* }
*
* @param gatherMap the map of indexes.
* @return the resulting Table.
*/
public Table gather(ColumnView gatherMap) {
```
These docs could be generated in batch by an AI and human-verified for correctness.
Contributor guide
Assessment
This issue has not been assessed yet.