You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ueshin (via GitHub)" <gi...@apache.org> on 2024/01/11 22:25:33 UTC

[PR] [SPARK-46684][PYTHON][CONNECT] Fix CoGroup.applyInPandas/Arrow to pass arguments properly [spark]

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

   ### What changes were proposed in this pull request?
   
   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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46684][PYTHON][CONNECT] Fix CoGroup.applyInPandas/Arrow to pass arguments properly [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #44695:
URL: https://github.com/apache/spark/pull/44695#issuecomment-1888408775

   Merged to master.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46684][PYTHON][CONNECT] Fix CoGroup.applyInPandas/Arrow to pass arguments properly [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #44695: [SPARK-46684][PYTHON][CONNECT] Fix CoGroup.applyInPandas/Arrow to pass arguments properly
URL: https://github.com/apache/spark/pull/44695


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org