Skip to content

Commit eb07f10

Browse files
CLN: move __finalize__ call into splitter (groupbt pandas-devGH-45363 follow-up)
1 parent 4e034ec commit eb07f10

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

pandas/core/generic.py

-16
Original file line numberDiff line numberDiff line change
@@ -285,22 +285,6 @@ def _init_mgr(
285285
mgr = mgr.astype(dtype=dtype)
286286
return mgr
287287

288-
@classmethod
289-
def _from_mgr(cls, mgr: Manager):
290-
"""
291-
Fastpath to create a new DataFrame/Series from just a BlockManager/ArrayManager.
292-
293-
Notes
294-
-----
295-
Skips setting `_flags` attribute; caller is responsible for doing so.
296-
"""
297-
obj = cls.__new__(cls)
298-
object.__setattr__(obj, "_is_copy", None)
299-
object.__setattr__(obj, "_mgr", mgr)
300-
object.__setattr__(obj, "_item_cache", {})
301-
object.__setattr__(obj, "_attrs", {})
302-
return obj
303-
304288
def _as_manager(self: NDFrameT, typ: str, copy: bool_t = True) -> NDFrameT:
305289
"""
306290
Private helper function to create a DataFrame with specific manager.

pandas/core/groupby/ops.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -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,9 @@ 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+
return sdata._constructor(mgr, name=sdata.name, fastpath=True).__finalize__(
1243+
sdata, method="groupby"
1244+
)
12491245

12501246

12511247
class FrameSplitter(DataSplitter):
@@ -1256,8 +1252,7 @@ def _chop(self, sdata: DataFrame, slice_obj: slice) -> DataFrame:
12561252
# else:
12571253
# return sdata.iloc[:, slice_obj]
12581254
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)
1255+
return sdata._constructor(mgr).__finalize__(sdata, method="groupby")
12611256

12621257

12631258
def get_splitter(

0 commit comments

Comments
 (0)