File tree 3 files changed +15
-1
lines changed
3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -491,6 +491,7 @@ Bug Fixes
491
491
- Bug in ``PeriodIndex`` construction returning a ``float64`` index in some circumstances (:issue:`13067`)
492
492
- Bug in ``.resample(..)`` with a ``PeriodIndex`` not changing its ``freq`` appropriately when empty (:issue:`13067`)
493
493
- Bug in ``.resample(..)`` with a ``PeriodIndex`` not retaining its type or name with an empty ``DataFrame`` appropriately when empty (:issue:`13212`)
494
+ - Bug in ``groupby(..).apply(..)`` when the passed function returns scalar values per group (:issue:`13468`).
494
495
- Bug in ``groupby(..).resample(..)`` where passing some keywords would raise an exception (:issue:`13235`)
495
496
- Bug in ``.tz_convert`` on a tz-aware ``DateTimeIndex`` that relied on index being sorted for correct results (:issue:`13306`)
496
497
- Bug in ``.tz_localize`` with ``dateutil.tz.tzlocal`` may return incorrect result (:issue:`13583`)
Original file line number Diff line number Diff line change @@ -3403,11 +3403,14 @@ def first_non_None_value(values):
3403
3403
3404
3404
return self ._reindex_output (result )
3405
3405
3406
+ # values are not series or array-like but scalars
3406
3407
else :
3407
3408
# only coerce dates if we find at least 1 datetime
3408
3409
coerce = True if any ([isinstance (x , Timestamp )
3409
3410
for x in values ]) else False
3410
- return (Series (values , index = key_index , name = self .name )
3411
+ # self.name not passed through to Series as the result
3412
+ # should not take the name of original selection of columns
3413
+ return (Series (values , index = key_index )
3411
3414
._convert (datetime = True ,
3412
3415
coerce = coerce ))
3413
3416
Original file line number Diff line number Diff line change @@ -2584,6 +2584,16 @@ def test_apply_series_yield_constant(self):
2584
2584
result = self .df .groupby (['A' , 'B' ])['C' ].apply (len )
2585
2585
self .assertEqual (result .index .names [:2 ], ('A' , 'B' ))
2586
2586
2587
+ def test_apply_frame_yield_constant (self ):
2588
+ # GH13568
2589
+ result = self .df .groupby (['A' , 'B' ]).apply (len )
2590
+ self .assertTrue (isinstance (result , Series ))
2591
+ self .assertIsNone (result .name )
2592
+
2593
+ result = self .df .groupby (['A' , 'B' ])[['C' , 'D' ]].apply (len )
2594
+ self .assertTrue (isinstance (result , Series ))
2595
+ self .assertIsNone (result .name )
2596
+
2587
2597
def test_apply_frame_to_series (self ):
2588
2598
grouped = self .df .groupby (['A' , 'B' ])
2589
2599
result = grouped .apply (len )
You can’t perform that action at this time.
0 commit comments