BUG: fix subclass metadata preservation in groupby column selection by jorisvandenbossche · Pull Request #56761 · pandas-dev/pandas (original) (raw)

This is a small regression that was introduced with #51090 (in pandas 2.0): before that PR, the column subselection in the groupby code was done with a standard __getitem__ call, while the PR introduced an optimized helper _getitem_nocopy to avoid the copy that a standard __getitem__ does. However, that new helper forgot to add a __finalize__ call after _constructor from a manager.

The reason we noticed this in geopandas (geopandas/geopandas#3130) was to update our tests for the apply deprecation to include group columns (for which one alternative is to specifically select the non-group columns, but so that didn't work with recent pandas versions)