@@ -354,35 +354,17 @@ def array_func(values: ArrayLike) -> ArrayLike:
354
354
)
355
355
return self ._reindex_output (ser )
356
356
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 ]
360
359
) -> Series :
361
360
"""
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.
377
362
"""
378
363
assert len (output ) == 1
379
-
380
- name = self .obj .name
381
- index = self .grouper .result_index
382
364
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
386
368
387
369
def _wrap_transformed_output (
388
370
self , output : Mapping [base .OutputKey , Series | ArrayLike ]
@@ -1614,46 +1596,19 @@ def _insert_inaxis_grouper_inplace(self, result: DataFrame) -> None:
1614
1596
if in_axis and name not in columns :
1615
1597
result .insert (0 , name , lev )
1616
1598
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 ]
1620
1601
) -> DataFrame :
1621
1602
"""
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.
1632
1604
"""
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 )
1655
1608
1656
- return self ._reindex_output (result )
1609
+ result = self .obj ._constructor (indexed_output )
1610
+ result .columns = columns
1611
+ return result
1657
1612
1658
1613
def _wrap_transformed_output (
1659
1614
self , output : Mapping [base .OutputKey , Series | ArrayLike ]
0 commit comments