ueshin opened a new pull request, #54285:
URL: https://github.com/apache/spark/pull/54285
### What changes were proposed in this pull request?
Deals with `include_groups` for `groupby.apply`.
- Added `include_groups` for `groupby.apply`
- with pandas 2
- `True` by default
- If set to `False`, it behaves like pandas 3
- with pandas 3
- `False` by default
- If set to `True`, it raises an exception
### Why are the changes needed?
`df.groupby.apply()` now has `include_groups=False` by default, which
differs from our behavior.
For example:
```py
>>> import pandas as pd
>>> pdf = pd.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"],
... )
```
- pandas 2
```py
>>> pd.__version__
'2.3.3'
>>> pdf.groupby("b").apply(lambda x: x + x.min())
a b c
b
1 0 2 2 2
1 3 2 5
2 2 6 4 18
3 3 8 6 32
5 4 10 10 50
8 5 12 16 72
>>> pdf.groupby("b").apply(lambda x: x + x.min(), include_groups=False)
a c
b
1 0 2 2
1 3 5
2 2 6 18
3 3 8 32
5 4 10 50
8 5 12 72
```
- pandas 3
```py
>>> pd.__version__
'3.0.0'
>>> pdf.groupby("b").apply(lambda x: x + x.min())
a c
b
1 0 2 2
1 3 5
2 2 6 18
3 3 8 32
5 4 10 50
8 5 12 72
>>> pdf.groupby("b").apply(lambda x: x + x.min(), include_groups=True)
Traceback (most recent call last):
...
ValueError: include_groups=True is no longer allowed.
```
### Does this PR introduce _any_ user-facing change?
Yes, it will behave more like pandas 3.
### How was this patch tested?
Updated 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]