Skip to content

Commit 005598c

Browse files
horaceklairhshadrach
authored andcommitted
TST: dropping of nuisance columns for groupby ops pandas-dev#38815 (pandas-dev#43674)
1 parent 9d6da6d commit 005598c

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

pandas/tests/groupby/test_groupby.py

+33-9
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,6 @@ def test_groupby_multi_corner(df):
863863

864864
def test_omit_nuisance(df):
865865
grouped = df.groupby("A")
866-
867-
result = grouped.mean()
868-
expected = df.loc[:, ["A", "C", "D"]].groupby("A").mean()
869-
tm.assert_frame_equal(result, expected)
870-
871866
agged = grouped.agg(np.mean)
872867
exp = grouped.mean()
873868
tm.assert_frame_equal(agged, exp)
@@ -886,14 +881,43 @@ def test_omit_nuisance(df):
886881
grouped.agg(lambda x: x.sum(0, numeric_only=False))
887882

888883

889-
def test_omit_nuisance_sem(df):
890-
# GH 38774 - sem should work with nuisance columns
884+
@pytest.mark.parametrize(
885+
"agg_function",
886+
["max", "min"],
887+
)
888+
def test_keep_nuisance_agg(df, agg_function):
889+
# GH 38815
890+
grouped = df.groupby("A")
891+
result = getattr(grouped, agg_function)()
892+
expected = result.copy()
893+
expected.loc["bar", "B"] = getattr(df.loc[df["A"] == "bar", "B"], agg_function)()
894+
expected.loc["foo", "B"] = getattr(df.loc[df["A"] == "foo", "B"], agg_function)()
895+
tm.assert_frame_equal(result, expected)
896+
897+
898+
@pytest.mark.parametrize(
899+
"agg_function",
900+
["sum", "mean", "prod", "std", "var", "median"],
901+
)
902+
def test_omit_nuisance_agg(df, agg_function):
903+
# GH 38774, GH 38815
891904
grouped = df.groupby("A")
892-
result = grouped.sem()
893-
expected = df.loc[:, ["A", "C", "D"]].groupby("A").sem()
905+
result = getattr(grouped, agg_function)()
906+
expected = getattr(df.loc[:, ["A", "C", "D"]].groupby("A"), agg_function)()
894907
tm.assert_frame_equal(result, expected)
895908

896909

910+
def test_omit_nuisance_warnings(df):
911+
# GH 38815
912+
with tm.assert_produces_warning(
913+
FutureWarning, filter_level="always", check_stacklevel=False
914+
):
915+
grouped = df.groupby("A")
916+
result = grouped.skew()
917+
expected = df.loc[:, ["A", "C", "D"]].groupby("A").skew()
918+
tm.assert_frame_equal(result, expected)
919+
920+
897921
def test_omit_nuisance_python_multiple(three_group):
898922
grouped = three_group.groupby(["A", "B"])
899923

0 commit comments

Comments
 (0)