Yikun commented on code in PR #37801:
URL: https://github.com/apache/spark/pull/37801#discussion_r964975991
##########
python/pyspark/pandas/groupby.py:
##########
@@ -895,6 +895,102 @@ def sem(col: Column) -> Column:
bool_to_numeric=True,
)
+ # TODO: 1, 'n' accepts list and slice; 2, implement 'dropna' parameter
+ def nth(self, n: int) -> FrameLike:
+ """
+ Take the nth row from each group.
+
+ .. versionadded:: 3.4.0
+
+ Parameters
+ ----------
+ n : int
+ A single nth value for the row
+
+ Returns
+ -------
+ Series or DataFrame
+
+ Notes
+ -----
+ There is a behavior difference between pandas-on-Spark and pandas:
+
+ * when there is no aggregation column, and `n` not equal to 0 or -1,
+ the returned empty dataframe may have an index with different lenght
`__len__`.
Review Comment:
```suggestion
```
##########
python/pyspark/pandas/groupby.py:
##########
@@ -895,6 +895,102 @@ def sem(col: Column) -> Column:
bool_to_numeric=True,
)
+ # TODO: 1, 'n' accepts list and slice; 2, implement 'dropna' parameter
+ def nth(self, n: int) -> FrameLike:
+ """
+ Take the nth row from each group.
+
Review Comment:
```
.. note:: There is a behavior difference between pandas-on-Spark and
pandas:
when there is no aggregation column, and `n` not equal to 0 or
-1,
the returned empty dataframe may have an index with different
lenght `__len__`.
```
--
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]