You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "ntjohnson1 (via GitHub)" <gi...@apache.org> on 2026/03/11 16:11:11 UTC
[PR] Add docstring examples for Aggregate statistical and regression functions [datafusion-python]
ntjohnson1 opened a new pull request, #1417:
URL: https://github.com/apache/datafusion-python/pull/1417
# Which issue does this PR close?
* Part 4 of https://github.com/apache/datafusion-python/pull/1400
* Related to https://github.com/apache/datafusion-python/issues/1394
# Rationale for this change
Add example usage to docstrings for Aggregate statistical and regression 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add docstring examples for Aggregate statistical and regression functions [datafusion-python]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #1417:
URL: https://github.com/apache/datafusion-python/pull/1417#discussion_r2929536951
##########
python/datafusion/functions.py:
##########
@@ -2127,6 +2161,15 @@ def covar(value_y: Expr, value_x: Expr, filter: Expr | None = None) -> Expr:
"""Computes the sample covariance.
This is an alias for :py:func:`covar_samp`.
+
+ Examples:
+ ---------
+ >>> ctx = dfn.SessionContext()
+ >>> df = ctx.from_pydict({"a": [1.0, 2.0, 3.0], "b": [4.0, 5.0, 6.0]})
+ >>> result = df.aggregate(
+ ... [], [dfn.functions.covar(dfn.col("a"), dfn.col("b")).alias("v")])
+ >>> result.collect_column("v")[0].as_py()
+ 1.0
Review Comment:
Since `covar()` is an alias of `covar_samp()`, and the new example is a verbatim duplicate of the covar_samp function’s example, do you think keeping the example only on `covar_samp()` and leaving the alias docstring short would avoid doc drift?
##########
python/datafusion/functions.py:
##########
@@ -2101,6 +2110,22 @@ def covar_pop(value_y: Expr, value_x: Expr, filter: Expr | None = None) -> Expr:
value_y: The dependent variable for covariance
value_x: The independent variable for covariance
filter: If provided, only compute against rows for which the filter is True
+
+ Examples:
+ ---------
+ >>> import builtins
+ >>> ctx = dfn.SessionContext()
+ >>> df = ctx.from_pydict({"a": [1.0, 2.0, 3.0], "b": [4.0, 5.0, 6.0]})
+ >>> result = df.aggregate(
+ ... [],
+ ... [dfn.functions.covar_pop(
+ ... dfn.col("a"), dfn.col("b")
+ ... ).alias("v")]
+ ... )
+ >>> builtins.round(
+ ... result.collect_column("v")[0].as_py(), 4
Review Comment:
This example can be simplified by choosing input values with an exact covariance result instead of importing `builtins` just to round the output.
That would make `covar_pop` read more like the surrounding examples.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add docstring examples for Aggregate statistical and regression functions [datafusion-python]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #1417:
URL: https://github.com/apache/datafusion-python/pull/1417#issuecomment-4072645714
@ntjohnson1
I'll merge this after you resolve the merge conflicts
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org