ueshin opened a new pull request #34160:
URL: https://github.com/apache/spark/pull/34160


   ### What changes were proposed in this pull request?
   
   Fix `DataFrameGroupBy.apply` without shortcut.
   
   ### Why are the changes needed?
   
   `DataFrameGroupBy.apply` without shortcut could raise an exception when it 
returns `Series`.
   
   ```py
   >>> ps.options.compute.shortcut_limit = 3
   >>> psdf = ps.DataFrame(
   ...     {"a": [1, 2, 3, 4, 5, 6], "b": [1, 1, 2, 3, 5, 8], "c": [1, 4, 9, 
16, 25, 36]},
   ...     columns=["a", "b", "c"],
   ... )
   >>> psdf.groupby("b").apply(lambda x: x["a"])
   org.apache.spark.api.python.PythonException: Traceback (most recent call 
last):
   ...
   ValueError: Length mismatch: Expected axis has 2 elements, new values have 3 
elements
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   The error above will be gone:
   
   ```py
   >>> psdf.groupby("b").apply(lambda x: x["a"])
   b
   1  0    1
      1    2
   2  2    3
   3  3    4
   5  4    5
   8  5    6
   Name: a, dtype: int64
   ```
   
   ### How was this patch tested?
   
   Added tests.


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