Skip to content

Commit f9c0398

Browse files
committed
TST: Add failing tests that idfentify GH13519 -- groupby + shift drops group columns
1 parent b1144fe commit f9c0398

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/groupby/test_groupby_shift.py

+22
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,25 @@ def test_group_shift_lose_timezone():
6464
result = df.groupby("a").shift(0).iloc[0]
6565
expected = Series({"date": now_dt}, name=result.name)
6666
tm.assert_series_equal(result, expected)
67+
68+
69+
def test_group_shift_lose_index_1():
70+
# GH 13519 -- test with as_index=False
71+
df = DataFrame({'K': [1, 1, 1, 2, 2, 3], 'V': [1, 2, 3, 4, 5, 6]})
72+
g = df.groupby('K', as_index=False)
73+
74+
expected = DataFrame({'K': [1, 1, 1, 2, 2, 3], 'V': [np.nan, 1, 2, np.nan, 4, np.nan]})
75+
result = g.shift(1)
76+
77+
tm.assert_frame_equal(expected, result)
78+
79+
80+
def test_group_shift_lose_index_2():
81+
# GH 13519 -- test with as_index=True
82+
df = DataFrame({'K': [1, 1, 1, 2, 2, 3], 'V': [1, 2, 3, 4, 5, 6]})
83+
g = df.groupby('K', as_index=True)
84+
85+
expected = DataFrame({'K': [1, 1, 1, 2, 2, 3], 'V': [np.nan, 1, 2, np.nan, 4, np.nan]}).set_index('K')
86+
result = g.shift(1)
87+
88+
tm.assert_frame_equal(expected, result)

0 commit comments

Comments
 (0)