Skip to content

Commit eb00c22

Browse files
authored
TST: Adding unit tests for named indexes resulting from empty datafra… (#43593)
1 parent 34d0498 commit eb00c22

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/groupby/test_groupby_shift_diff.py

+18
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,21 @@ def test_group_diff_object_raises(object_dtype):
113113
)
114114
with pytest.raises(TypeError, match=r"unsupported operand type\(s\) for -"):
115115
df.groupby("a")["b"].diff()
116+
117+
118+
def test_empty_shift_with_fill():
119+
# GH 41264, single-index check
120+
df = DataFrame(columns=["a", "b", "c"])
121+
shifted = df.groupby(["a"]).shift(1)
122+
shifted_with_fill = df.groupby(["a"]).shift(1, fill_value=0)
123+
tm.assert_frame_equal(shifted, shifted_with_fill)
124+
tm.assert_index_equal(shifted.index, shifted_with_fill.index)
125+
126+
127+
def test_multindex_empty_shift_with_fill():
128+
# GH 41264, multi-index check
129+
df = DataFrame(columns=["a", "b", "c"])
130+
shifted = df.groupby(["a", "b"]).shift(1)
131+
shifted_with_fill = df.groupby(["a", "b"]).shift(1, fill_value=0)
132+
tm.assert_frame_equal(shifted, shifted_with_fill)
133+
tm.assert_index_equal(shifted.index, shifted_with_fill.index)

0 commit comments

Comments
 (0)