Skip to content

Commit e014e0f

Browse files
BUG: groupby apply on selected columns yielding scalar (GH13568)
1 parent 2655dae commit e014e0f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.18.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ Bug Fixes
478478
- Bug in ``PeriodIndex`` construction returning a ``float64`` index in some circumstances (:issue:`13067`)
479479
- Bug in ``.resample(..)`` with a ``PeriodIndex`` not changing its ``freq`` appropriately when empty (:issue:`13067`)
480480
- Bug in ``.resample(..)`` with a ``PeriodIndex`` not retaining its type or name with an empty ``DataFrame`` appropriately when empty (:issue:`13212`)
481+
- Bug in ``groupby(..).apply(..)`` when the passed function returns scalar values per group (:issue:`13468`).
481482
- Bug in ``groupby(..).resample(..)`` where passing some keywords would raise an exception (:issue:`13235`)
482483
- Bug in ``.tz_convert`` on a tz-aware ``DateTimeIndex`` that relied on index being sorted for correct results (:issue:`13306`)
483484
- Bug in ``pd.read_hdf()`` where attempting to load an HDF file with a single dataset, that had one or more categorical columns, failed unless the key argument was set to the name of the dataset. (:issue:`13231`)

pandas/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ def first_non_None_value(values):
34073407
# only coerce dates if we find at least 1 datetime
34083408
coerce = True if any([isinstance(x, Timestamp)
34093409
for x in values]) else False
3410-
return (Series(values, index=key_index, name=self.name)
3410+
return (Series(values, index=key_index)
34113411
._convert(datetime=True,
34123412
coerce=coerce))
34133413

pandas/tests/test_groupby.py

+10
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,16 @@ def test_apply_series_yield_constant(self):
25842584
result = self.df.groupby(['A', 'B'])['C'].apply(len)
25852585
self.assertEqual(result.index.names[:2], ('A', 'B'))
25862586

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+
25872597
def test_apply_frame_to_series(self):
25882598
grouped = self.df.groupby(['A', 'B'])
25892599
result = grouped.apply(len)

0 commit comments

Comments
 (0)