Skip to content

Commit 9be757b

Browse files
ganevgvproost
authored andcommitted
TST: add test for ffill/bfill for non unique multilevel (pandas-dev#29763)
1 parent 6e085ac commit 9be757b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pandas/tests/groupby/test_transform.py

+35
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,41 @@ def test_pct_change(test_series, freq, periods, fill_method, limit):
911911
tm.assert_frame_equal(result, expected.to_frame("vals"))
912912

913913

914+
@pytest.mark.parametrize(
915+
"func, expected_status",
916+
[
917+
("ffill", ["shrt", "shrt", "lng", np.nan, "shrt", "ntrl", "ntrl"]),
918+
("bfill", ["shrt", "lng", "lng", "shrt", "shrt", "ntrl", np.nan]),
919+
],
920+
)
921+
def test_ffill_bfill_non_unique_multilevel(func, expected_status):
922+
# GH 19437
923+
date = pd.to_datetime(
924+
[
925+
"2018-01-01",
926+
"2018-01-01",
927+
"2018-01-01",
928+
"2018-01-01",
929+
"2018-01-02",
930+
"2018-01-01",
931+
"2018-01-02",
932+
]
933+
)
934+
symbol = ["MSFT", "MSFT", "MSFT", "AAPL", "AAPL", "TSLA", "TSLA"]
935+
status = ["shrt", np.nan, "lng", np.nan, "shrt", "ntrl", np.nan]
936+
937+
df = DataFrame({"date": date, "symbol": symbol, "status": status})
938+
df = df.set_index(["date", "symbol"])
939+
result = getattr(df.groupby("symbol")["status"], func)()
940+
941+
index = MultiIndex.from_tuples(
942+
tuples=list(zip(*[date, symbol])), names=["date", "symbol"]
943+
)
944+
expected = Series(expected_status, index=index, name="status")
945+
946+
tm.assert_series_equal(result, expected)
947+
948+
914949
@pytest.mark.parametrize("func", [np.any, np.all])
915950
def test_any_all_np_func(func):
916951
# GH 20653

0 commit comments

Comments
 (0)