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 2026/02/18 00:17:40 UTC
[PR] [SPARK-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).apply` with dict [spark]
ueshin opened a new pull request, #54352:
URL: https://github.com/apache/spark/pull/54352
### What changes were proposed in this pull request?
This is a follow-up of apache/spark#54276.
Fixes `groupby(as_index=False).apply` with dict.
### Why are the changes needed?
The case of `groupby(as_index=False).apply` with dict was missing at apache/spark#54276.
```py
>>> psdf = ps.DataFrame(
... {"A": [1, 1, 2, 2], "B": [1, 2, 3, 4], "C": [0.362, 0.227, 1.267, -0.562]}
... )
>>> psdf.groupby(psdf.A, as_index=False).agg({"B": "min", "C": "sum"})
A B C
0 1 1 0.589
1 2 3 0.705
>>>
>>> psdf.groupby(psdf.A + 1, as_index=False).agg({"B": "min", "C": "sum"})
B C
0 1 0.589
1 3 0.705
```
whereas pandas 3:
```py
>>> pdf = pd.DataFrame(
... {"A": [1, 1, 2, 2], "B": [1, 2, 3, 4], "C": [0.362, 0.227, 1.267, -0.562]}
... )
>>> pdf.groupby(pdf.A, as_index=False).agg({"B": "min", "C": "sum"})
A B C
0 1 1 0.589
1 2 3 0.705
>>>
>>> pdf.groupby(pdf.A + 1, as_index=False).agg({"B": "min", "C": "sum"})
A B C
0 2 1 0.589
1 3 3 0.705
```
### Does this PR introduce _any_ user-facing change?
Yes, it will behave more like pandas 3.
### How was this patch tested?
The existing tests should pass.
### Was this patch authored or co-authored using generative AI tooling?
Codex (GPT-5.3-Codex)
--
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-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).agg` with dict [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #54352:
URL: https://github.com/apache/spark/pull/54352#discussion_r2824127362
##########
python/pyspark/pandas/groupby.py:
##########
@@ -329,7 +329,7 @@ def aggregate(
i for i, gkey in enumerate(self._groupkeys) if gkey._psdf is not self._psdf
)
else:
- column_names = [column.name for column in self._agg_columns]
+ column_names = set(func_or_funcs)
Review Comment:
`func_or_funcs` can be `str` or `list` as the input, too.
```py
pdf.groupby(pkey).agg("sum")
pdf.groupby(pkey).agg(["sum"])
```
The PR title and description mention the case that uses `dict` instead of them.
We can directly use `func_or_funcs`, or `list(func_or_funcs)` for `column_names`, but I'd like to make it clear using the keys and `set` should be faster than `list`.
--
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-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).apply` with dict [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #54352:
URL: https://github.com/apache/spark/pull/54352#issuecomment-3917757063
cc @gaogaotiantian @HyukjinKwon @zhengruifeng
--
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-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).agg` with dict [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #54352:
URL: https://github.com/apache/spark/pull/54352#issuecomment-3922833009
Merged to master for Apache Spark 4.2.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: 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-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).agg` with dict [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #54352:
URL: https://github.com/apache/spark/pull/54352#discussion_r2823986814
##########
python/pyspark/pandas/groupby.py:
##########
@@ -329,7 +329,7 @@ def aggregate(
i for i, gkey in enumerate(self._groupkeys) if gkey._psdf is not self._psdf
)
else:
- column_names = [column.name for column in self._agg_columns]
+ column_names = set(func_or_funcs)
Review Comment:
This is `set` instead of `dict`, isn't it, @ueshin ? I'm a little confused with the PR title and description.
> Fixes groupby(as_index=False).agg with *dict*.
--
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-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).agg` with dict [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #54352:
URL: https://github.com/apache/spark/pull/54352#discussion_r2824136010
##########
python/pyspark/pandas/groupby.py:
##########
@@ -329,7 +329,7 @@ def aggregate(
i for i, gkey in enumerate(self._groupkeys) if gkey._psdf is not self._psdf
)
else:
- column_names = [column.name for column in self._agg_columns]
+ column_names = set(func_or_funcs)
Review Comment:
Got it. So, it's not about this change, but it's about the whole function args. Thank you, @ueshin .
--
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-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).agg` with dict [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun closed pull request #54352: [SPARK-55490][PS][FOLLOW-UP] Fix `groupby(as_index=False).agg` with dict
URL: https://github.com/apache/spark/pull/54352
--
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