Add docstring examples for Aggregate window functions#1418
Open
ntjohnson1 wants to merge 1 commit intoapache:mainfrom
Open
Add docstring examples for Aggregate window functions#1418ntjohnson1 wants to merge 1 commit intoapache:mainfrom
ntjohnson1 wants to merge 1 commit intoapache:mainfrom
Conversation
Add example usage to docstrings for Aggregate window functions to improve documentation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kosiew
reviewed
Mar 13, 2026
Contributor
kosiew
left a comment
There was a problem hiding this comment.
@ntjohnson1
Thanks for working on this.
Comment on lines
2518
to
+2524
| df.aggregate([], first_value(col("a"), order_by="ts")) | ||
|
|
||
| Examples: | ||
| --------- | ||
| >>> ctx = dfn.SessionContext() | ||
| >>> df = ctx.from_pydict({"a": [10, 20, 30]}) | ||
| >>> result = df.aggregate([], [dfn.functions.first_value(dfn.col("a")).alias("v")]) |
Contributor
There was a problem hiding this comment.
2518: df.aggregate([], expr)
2524: ...df.aggregate([], [expr])
Mixing both forms inside the same docstring makes the API shape feel less crisp than it could be.
Same observation for first_value, last_value, and nth_value
Comment on lines
+3082
to
+3092
| >>> import builtins | ||
| >>> result = df.select( | ||
| ... dfn.col("a"), | ||
| ... dfn.functions.cume_dist( | ||
| ... order_by="a" | ||
| ... ).alias("cd") | ||
| ... ) | ||
| >>> [builtins.round(x, 4) for x in | ||
| ... result.sort(dfn.col("a") | ||
| ... ).collect_column("cd").to_pylist()] | ||
| [0.6667, 0.6667, 1.0] |
Contributor
There was a problem hiding this comment.
I think this would be a simpler example without builtin:
>>> ctx = dfn.SessionContext()
>>> df = ctx.from_pydict({"a": [1, 2, 2, 3]})
>>> result = df.select(cume_dist(col("a"))).collect()[0]
>>> rounded = [round(x, 2) for x in result.column(0)]
>>> rounded
[0.25, 0.75, 0.75, 1.0]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Add example usage to docstrings for Aggregate window functions to improve documentation.
What changes are included in this PR?
The first PR was basically adding a docstring to everything in functions. I broke it apart into a PR (that already merged) for the infra. I then reviewed and merged an example PR of adding the docstrings in parts. This is now the follow up opening a handful of PRs for the remaining functions in functions.py Everything is co-authored with Claude since I used claude to extend the handwritten examples I wrote for reference and to split apart the large PR rather than doing it manually.
I've reviewed all the code prior to PR.
Are there any user-facing changes?
No