@@ -354,35 +354,17 @@ def array_func(values: ArrayLike) -> ArrayLike:
354354 )
355355 return self ._reindex_output (ser )
356356
357- def _wrap_aggregated_output (
358- self ,
359- output : Mapping [base .OutputKey , Series | ArrayLike ],
357+ def _indexed_output_to_ndframe (
358+ self , output : Mapping [base .OutputKey , ArrayLike ]
360359 ) -> Series :
361360 """
362- Wraps the output of a SeriesGroupBy aggregation into the expected result.
363-
364- Parameters
365- ----------
366- output : Mapping[base.OutputKey, Union[Series, ArrayLike]]
367- Data to wrap.
368-
369- Returns
370- -------
371- Series
372-
373- Notes
374- -----
375- In the vast majority of cases output will only contain one element.
376- The exception is operations that expand dimensions, like ohlc.
361+ Wrap the dict result of a GroupBy aggregation into a Series.
377362 """
378363 assert len (output ) == 1
379-
380- name = self .obj .name
381- index = self .grouper .result_index
382364 values = next (iter (output .values ()))
383-
384- result = self .obj ._constructor ( values , index = index , name = name )
385- return self . _reindex_output ( result )
365+ result = self . obj . _constructor ( values )
366+ result . name = self .obj .name
367+ return result
386368
387369 def _wrap_transformed_output (
388370 self , output : Mapping [base .OutputKey , Series | ArrayLike ]
@@ -1614,46 +1596,19 @@ def _insert_inaxis_grouper_inplace(self, result: DataFrame) -> None:
16141596 if in_axis and name not in columns :
16151597 result .insert (0 , name , lev )
16161598
1617- def _wrap_aggregated_output (
1618- self ,
1619- output : Mapping [base .OutputKey , Series | ArrayLike ],
1599+ def _indexed_output_to_ndframe (
1600+ self , output : Mapping [base .OutputKey , ArrayLike ]
16201601 ) -> DataFrame :
16211602 """
1622- Wraps the output of DataFrameGroupBy aggregations into the expected result.
1623-
1624- Parameters
1625- ----------
1626- output : Mapping[base.OutputKey, Union[Series, np.ndarray]]
1627- Data to wrap.
1628-
1629- Returns
1630- -------
1631- DataFrame
1603+ Wrap the dict result of a GroupBy aggregation into a DataFrame.
16321604 """
1633- if isinstance (output , DataFrame ):
1634- result = output
1635- else :
1636- indexed_output = {key .position : val for key , val in output .items ()}
1637- columns = Index ([key .label for key in output ])
1638- columns ._set_names (self ._obj_with_exclusions ._get_axis (1 - self .axis ).names )
1639-
1640- result = self .obj ._constructor (indexed_output )
1641- result .columns = columns
1642-
1643- if not self .as_index :
1644- self ._insert_inaxis_grouper_inplace (result )
1645- result = result ._consolidate ()
1646- else :
1647- result .index = self .grouper .result_index
1648-
1649- if self .axis == 1 :
1650- result = result .T
1651- if result .index .equals (self .obj .index ):
1652- # Retain e.g. DatetimeIndex/TimedeltaIndex freq
1653- result .index = self .obj .index .copy ()
1654- # TODO: Do this more systematically
1605+ indexed_output = {key .position : val for key , val in output .items ()}
1606+ columns = Index ([key .label for key in output ])
1607+ columns ._set_names (self ._obj_with_exclusions ._get_axis (1 - self .axis ).names )
16551608
1656- return self ._reindex_output (result )
1609+ result = self .obj ._constructor (indexed_output )
1610+ result .columns = columns
1611+ return result
16571612
16581613 def _wrap_transformed_output (
16591614 self , output : Mapping [base .OutputKey , Series | ArrayLike ]
0 commit comments