Skip to content

BUG: Fix groupby.apply() dropping _metadata from subclassed DataFrame #62135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MengAiDev
Copy link

When extending pandas.DataFrame by subclassing, most operations preserve the _metadata attributes. This fix ensures that groupby.apply() also preserves these fields, making it consistent with other groupby operations like groupby.sum().

Fixes #62134

When extending pandas.DataFrame by subclassing, most operations preserve
the _metadata attributes. This fix ensures that groupby.apply() also
preserves these fields, making it consistent with other groupby operations
like groupby.sum().

Fixes pandas-dev#62134
@MengAiDev MengAiDev requested a review from rhshadrach as a code owner August 18, 2025 01:09
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Why not call __finalize__ instead?

- Update metadata preservation logic for DataFrames and Series in groupby operations
- Fix DataFrame.__setitem__ with MultiIndex columns and scalar indexer
- Adjust formatting and naming conventions in the code
@MengAiDev
Copy link
Author

Thanks for the PR! Why not call __finalize__ instead?

Thanks!

… scalar value

- Address issue where name attribute was lost when setting new column with scalar value and tuple key in MultiIndex DataFrame
- Implement check for tuple key and scalar value in MultiIndex DataFrame
- Create Series with proper name to ensure name attribute matches the key
- Update test case to assert Series name in scalar assignment with MultiIndex
@MengAiDev
Copy link
Author

MengAiDev commented Aug 18, 2025

@rhshadrach
Copy link
Member

Seems related to the change you're making here in frame.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: groupby.apply() drops _metadata from subclassed DataFrame
2 participants