@@ -705,17 +705,14 @@ def get_iterator(
705705 """
706706 splitter = self ._get_splitter (data , axis = axis )
707707 keys = self .group_keys_seq
708- for key , group in zip (keys , splitter ):
709- yield key , group .__finalize__ (data , method = "groupby" )
708+ yield from zip (keys , splitter )
710709
711710 @final
712711 def _get_splitter (self , data : NDFrame , axis : int = 0 ) -> DataSplitter :
713712 """
714713 Returns
715714 -------
716715 Generator yielding subsetted objects
717-
718- __finalize__ has not been called for the subsetted objects returned.
719716 """
720717 ids , _ , ngroups = self .group_info
721718 return get_splitter (data , ids , ngroups , axis = axis )
@@ -753,7 +750,6 @@ def apply(
753750 zipped = zip (group_keys , splitter )
754751
755752 for key , group in zipped :
756- group = group .__finalize__ (data , method = "groupby" )
757753 object .__setattr__ (group , "name" , key )
758754
759755 # group might be modified
@@ -1001,7 +997,6 @@ def _aggregate_series_pure_python(
1001997 splitter = get_splitter (obj , ids , ngroups , axis = 0 )
1002998
1003999 for i , group in enumerate (splitter ):
1004- group = group .__finalize__ (obj , method = "groupby" )
10051000 res = func (group )
10061001 res = libreduction .extract_result (res )
10071002
@@ -1244,8 +1239,8 @@ class SeriesSplitter(DataSplitter):
12441239 def _chop (self , sdata : Series , slice_obj : slice ) -> Series :
12451240 # fastpath equivalent to `sdata.iloc[slice_obj]`
12461241 mgr = sdata ._mgr .get_slice (slice_obj )
1247- # __finalize__ not called here, must be applied by caller if applicable
1248- return sdata . _constructor ( mgr , name = sdata . name , fastpath = True )
1242+ ser = sdata . _constructor ( mgr , name = sdata . name , fastpath = True )
1243+ return ser . __finalize__ ( sdata , method = "groupby" )
12491244
12501245
12511246class FrameSplitter (DataSplitter ):
@@ -1256,8 +1251,8 @@ def _chop(self, sdata: DataFrame, slice_obj: slice) -> DataFrame:
12561251 # else:
12571252 # return sdata.iloc[:, slice_obj]
12581253 mgr = sdata ._mgr .get_slice (slice_obj , axis = 1 - self .axis )
1259- # __finalize__ not called here, must be applied by caller if applicable
1260- return sdata . _constructor ( mgr )
1254+ df = sdata . _constructor ( mgr )
1255+ return df . __finalize__ ( sdata , method = "groupby" )
12611256
12621257
12631258def get_splitter (
0 commit comments