Skip to content

Commit dfcb534

Browse files
committed
Added test case for groupby fill methods
1 parent 49812cf commit dfcb534

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/groupby/test_groupby.py

+19
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,25 @@ def test_rank_object_raises(self, ties_method, ascending, na_option,
20612061
ascending=ascending,
20622062
na_option=na_option, pct=pct)
20632063

2064+
@pytest.mark.parametrize("fill_method,limit,exp_vals", [
2065+
("ffill", None,
2066+
[np.nan, np.nan, 'foo', 'foo', 'foo', 'bar', 'bar', 'bar']),
2067+
("ffill", 1,
2068+
[np.nan, np.nan, 'foo', 'foo', np.nan, 'bar', 'bar', np.nan]),
2069+
("bfill", None,
2070+
['foo', 'foo', 'foo', 'bar', 'bar', 'bar', np.nan, np.nan]),
2071+
("bfill", 1,
2072+
[np.nan, 'foo', 'foo', np.nan, 'bar', 'bar', np.nan, np.nan])
2073+
])
2074+
def test_group_fill_methods(self, fill_method, limit, exp_vals):
2075+
vals = [np.nan, np.nan, 'foo', np.nan, np.nan, 'bar', np.nan, np.nan]
2076+
keys = ['a'] * len(vals) + ['b'] * len(vals)
2077+
df = DataFrame({'key': keys, 'val': vals * 2})
2078+
result = getattr(df.groupby('key'), fill_method)(limit=limit)
2079+
2080+
exp = DataFrame({'key': keys, 'val': exp_vals * 2})
2081+
assert_frame_equal(result, exp)
2082+
20642083
def test_dont_clobber_name_column(self):
20652084
df = DataFrame({'key': ['a', 'a', 'a', 'b', 'b', 'b'],
20662085
'name': ['foo', 'bar', 'baz'] * 2})

0 commit comments

Comments
 (0)