Skip to content

Commit 066783c

Browse files
committed
Merge branch 'newgroupby' of https://github.com/terrytangyuan/pandas into terrytangyuan-newgroupby
2 parents 5567bf0 + 7a6e3b1 commit 066783c

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

doc/source/whatsnew/v0.17.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ Bug Fixes
951951

952952

953953
- Bug in ``to_datetime`` and ``to_timedelta`` causing ``Index`` name to be lost (:issue:`10875`)
954-
954+
- Bug in ``len(DataFrame.groupby)`` causing ``IndexError`` when there's a column containing only NaNs (:issue: `11016`)
955955

956956
- Bug that caused segfault when resampling an empty Series (:issue:`10228`)
957957
- Bug in ``DatetimeIndex`` and ``PeriodIndex.value_counts`` resets name from its result, but retains in result's ``Index``. (:issue:`10150`)

pandas/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def __init__(self, obj, keys=None, axis=0, level=None,
400400
self.exclusions = set(exclusions) if exclusions else set()
401401

402402
def __len__(self):
403-
return len(self.indices)
403+
return len(self.groups)
404404

405405
def __unicode__(self):
406406
# TODO: Better unicode/repr for GroupBy object

pandas/tests/test_groupby.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,12 @@ def test_len(self):
837837
expected = len(set([(x.year, x.month) for x in df.index]))
838838
self.assertEqual(len(grouped), expected)
839839

840+
# issue 11016
841+
df = pd.DataFrame(dict(a=[np.nan]*3, b=[1,2,3]))
842+
self.assertEqual(len(df.groupby(('a'))), 0)
843+
self.assertEqual(len(df.groupby(('b'))), 3)
844+
self.assertEqual(len(df.groupby(('a', 'b'))), 3)
845+
840846
def test_groups(self):
841847
grouped = self.df.groupby(['A'])
842848
groups = grouped.groups

0 commit comments

Comments
 (0)