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

   ### What changes were proposed in this pull request?
   
   This is a backport of #44695.
   
   Fix `CoGroup.applyInPandas/Arrow` to pass arguments properly.
   
   ### Why are the changes needed?
   
   In Spark Connect, `CoGroup.applyInPandas/Arrow` doesn't take arguments 
properly, so the arguments of the UDF can be broken:
   
   ```py
   >>> import pandas as pd
   >>>
   >>> df1 = spark.createDataFrame(
   ...     [(1, 1.0, "a"), (2, 2.0, "b"), (1, 3.0, "c"), (2, 4.0, "d")], ("id", 
"v1", "v2")
   ... )
   >>> df2 = spark.createDataFrame([(1, "x"), (2, "y"), (1, "z")], ("id", "v3"))
   >>>
   >>> def summarize(left, right):
   ...     return pd.DataFrame(
   ...         {
   ...             "left_rows": [len(left)],
   ...             "left_columns": [len(left.columns)],
   ...             "right_rows": [len(right)],
   ...             "right_columns": [len(right.columns)],
   ...         }
   ...     )
   ...
   >>> df = (
   ...     df1.groupby("id")
   ...     .cogroup(df2.groupby("id"))
   ...     .applyInPandas(
   ...         summarize,
   ...         schema="left_rows long, left_columns long, right_rows long, 
right_columns long",
   ...     )
   ... )
   >>>
   >>> df.show()
   +---------+------------+----------+-------------+
   |left_rows|left_columns|right_rows|right_columns|
   +---------+------------+----------+-------------+
   |        2|           1|         2|            1|
   |        2|           1|         1|            1|
   +---------+------------+----------+-------------+
   ```
   
   The result should be:
   
   ```py
   +---------+------------+----------+-------------+
   |left_rows|left_columns|right_rows|right_columns|
   +---------+------------+----------+-------------+
   |        2|           3|         2|            2|
   |        2|           3|         1|            2|
   +---------+------------+----------+-------------+
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   This is a bug fix.
   
   ### How was this patch tested?
   
   Added the related tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   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: [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