Skip to content

Commit 74ed10c

Browse files
committed
TST: Groupby.filter dropna=False with empty group (#10780)
1 parent 3ccb501 commit 74ed10c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pandas/tests/groupby/test_filters.py

+8
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,14 @@ def test_filter_non_bool_raises(self):
596596
with tm.assertRaisesRegexp(TypeError, 'filter function returned a.*'):
597597
df.groupby('a').filter(lambda g: g.c.mean())
598598

599+
def test_filter_dropna_false_with_empty_groups(self):
600+
# GH 10780
601+
data = pd.Series(np.random.rand(9), index=np.repeat([1, 2, 3], 3))
602+
groupped = data.groupby(level=0)
603+
result = groupped.filter(lambda x: x.mean() > 1, dropna=False)
604+
expected = pd.Series([np.nan] * 9, index=np.repeat([1, 2, 3], 3))
605+
tm.assert_series_equal(result, expected)
606+
599607

600608
def assert_fp_equal(a, b):
601609
assert (np.abs(a - b) < 1e-12).all()

0 commit comments

Comments
 (0)