Skip to content

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.

Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Sep 20, 2025
@rhshadrach
Copy link
Member

Thanks for the PR, closing as stale for now. If you'd like to continue, fixup the failing tests and happy to reopen!

@rhshadrach rhshadrach closed this Sep 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants