Skip to content

Commit 361b62e

Browse files
TST: GroupBy.ffill on a multi-index dataframe (pandas-dev#55408)
* add new automated test with ffill on a multi-index dataframe This test checks whether the ffill method works correctly on a multi-index dataframe. In it, we define a dataframe with indexes [0, 1, 2, 0, 1, 2] and column "a" with values [1, 2, NaN, 3, 4, 5]. We group this dataframe by columns (level = 0) and shift it by one, so we have: 0: [1, 3] -> [NaN, 1] 1: [2, 4] -> [NaN, 2] 2: [NaN, 5] -> [NaN, NaN] Then, since index order remain the same, if we apply ffill method, it should give us a dataframe with column "a" equal to [NaN, NaN, NaN, 1, 2, 2]. Co-authored-by: José Lucas Silva Mayer <[email protected]> Co-authored-by: Willian Wang <[email protected]> * remove shift and add cast dataframe dtype to float Signed-off-by: José Lucas Silva Mayer <[email protected]> * remove check of dataframe dtype on assert Signed-off-by: José Lucas Silva Mayer <[email protected]> --------- Signed-off-by: José Lucas Silva Mayer <[email protected]> Co-authored-by: Willian Wang <[email protected]>
1 parent dc3035d commit 361b62e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pandas/tests/groupby/test_groupby.py

+9
Original file line numberDiff line numberDiff line change
@@ -3242,3 +3242,12 @@ def test_get_group_axis_1():
32423242
}
32433243
)
32443244
tm.assert_frame_equal(result, expected)
3245+
3246+
3247+
def test_groupby_ffill_with_duplicated_index():
3248+
# GH#43412
3249+
df = DataFrame({"a": [1, 2, 3, 4, np.nan, np.nan]}, index=[0, 1, 2, 0, 1, 2])
3250+
3251+
result = df.groupby(level=0).ffill()
3252+
expected = DataFrame({"a": [1, 2, 3, 4, 2, 3]}, index=[0, 1, 2, 0, 1, 2])
3253+
tm.assert_frame_equal(result, expected, check_dtype=False)

0 commit comments

Comments
 (0)