Skip to content

Complete doc string examples for functions.py#1435

Merged
timsaucer merged 12 commits intoapache:mainfrom
rerun-io:nick/polish_docstrings
Mar 27, 2026
Merged

Complete doc string examples for functions.py#1435
timsaucer merged 12 commits intoapache:mainfrom
rerun-io:nick/polish_docstrings

Conversation

@ntjohnson1
Copy link
Copy Markdown
Contributor

@ntjohnson1 ntjohnson1 commented Mar 18, 2026

Which issue does this PR close?

Closes #1434 and #1433

Rationale for this change

Added coverage over MOST functions in functions.py with examples but split things up to be reviewable. There were a couple global notes that got lost across the many PRs

This relies on #1418 landing first since I branched from there. (MERGED and rebased)
This PR isn't as large as the diff suggests because a lot of changes are simple formatting. Reviewing by commit should make it much easier.

  • Cover remaining functions
  • Format aliases with See Also blocks
  • Format Examples to match google doc string style (biggest churn)
  • Remove unnecessary use of builtins
  • Cover optional arguments (in multiple commits to chunk it up)

@ntjohnson1 ntjohnson1 force-pushed the nick/polish_docstrings branch from 021597f to 6a5991c Compare March 19, 2026 14:12
@ntjohnson1 ntjohnson1 marked this pull request as ready for review March 19, 2026 14:18
Copy link
Copy Markdown
Member

@timsaucer timsaucer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work!

Comment on lines +507 to +511
... dfn.functions.alias(
... dfn.col("a"), "b", metadata={"info": "test"}
... )
... ).collect_column("b")[0].as_py()
1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really demonstrate the metadata output. Instead of converting to py maybe we need to check something else. I'm not 100% sure what right now but I'll take a look after finishing this review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df.select(
    dfn.functions.alias(
        dfn.col("a"), "b", metadata={"info": "test"}
        )
).schema()

This does show the metadata. Converting to pyarrow scalar appears to drop it. Converting to a pyarrow table does keep the metadata on the table, but then selecting the appropriate array still you can't see the metadata. :|

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I printed out the schema instead

Comment on lines +1188 to +1189
... dfn.col("a"), dfn.lit(10), dfn.lit(".")
... ).alias("lpad"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should use keywords to help make it more explicit, but not a blocker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added keyword for optional args here

Comment on lines +3640 to +3653
>>> ctx = dfn.SessionContext()
>>> df = ctx.from_pydict({"a": [1, 2, 3]})
>>> result = df.aggregate([], [dfn.functions.count(dfn.col("a")).alias("v")])
>>> result.collect_column("v")[0].as_py()
3

>>> df = ctx.from_pydict({"a": [1, 1, 2, 3]})
>>> result = df.aggregate(
... [], [dfn.functions.count(
... dfn.col("a"), distinct=True,
... filter=dfn.col("a") > dfn.lit(1),
... ).alias("v")])
>>> result.collect_column("v")[0].as_py()
2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be slightly easier for users to see the difference in the examples if they had the same formatting but I bet it's the linter making the call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter is a little odd inside the docstrings so it's semi linter supported. I did a quick pass to make the formatting more similar throughout the multi example situations.

@timsaucer timsaucer merged commit acd9a8d into apache:main Mar 27, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add full example coverage to functions

2 participants