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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to