kosiew commented on code in PR #1418:
URL: 
https://github.com/apache/datafusion-python/pull/1418#discussion_r2929595651


##########
python/datafusion/functions.py:
##########
@@ -2516,6 +2516,14 @@ def first_value(
     For example::
 
         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")])

Review 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`



##########
python/datafusion/functions.py:
##########
@@ -2995,6 +3074,22 @@ def cume_dist(
     For example::
 
         cume_dist(order_by="points")
+
+    Examples:
+    ---------
+    >>> ctx = dfn.SessionContext()
+    >>> df = ctx.from_pydict({"a": [10, 10, 20]})
+    >>> 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]

Review 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 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