Skip to content

Parametrized groupby allowlist test #38829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 31, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions pandas/tests/groupby/test_allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,9 @@ def test_groupby_function_rename(mframe):
assert f.__name__ == name


@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
def test_groupby_selection_with_methods(df):
# some methods which require DatetimeIndex
rng = date_range("2014", periods=len(df))
df.index = rng

g = df.groupby(["A"])[["C"]]
g_exp = df[["C"]].groupby(df["A"])
# TODO check groupby with > 1 col ?

# methods which are called as .foo()
methods = [
@pytest.mark.parametrize(
"method",
[
"count",
"corr",
"cummax",
Expand All @@ -370,20 +361,45 @@ def test_groupby_selection_with_methods(df):
"ffill",
"bfill",
"pct_change",
]
],
)
@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
def test_groupby_selection_with_methods(df, method):
# some methods which require DatetimeIndex
rng = date_range("2014", periods=len(df))
df.index = rng

g = df.groupby(["A"])[["C"]]
g_exp = df[["C"]].groupby(df["A"])
# TODO check groupby with > 1 col ?

res = getattr(g, method)()
exp = getattr(g_exp, method)()

# should always be frames!
tm.assert_frame_equal(res, exp)

for m in methods:
res = getattr(g, m)()
exp = getattr(g_exp, m)()

# should always be frames!
tm.assert_frame_equal(res, exp)
def test_groupby_selection_tshift_raises(df):
rng = date_range("2014", periods=len(df))
df.index = rng

g = df.groupby(["A"])[["C"]]

# check that the index cache is cleared
with pytest.raises(ValueError, match="Freq was not set in the index"):
# GH#35937
g.tshift()


def test_groupby_selection_other_methods(df):
# some methods which require DatetimeIndex
rng = date_range("2014", periods=len(df))
df.index = rng

g = df.groupby(["A"])[["C"]]
g_exp = df[["C"]].groupby(df["A"])

# methods which aren't just .foo()
tm.assert_frame_equal(g.fillna(0), g_exp.fillna(0))
tm.assert_frame_equal(g.dtypes, g_exp.dtypes)
Expand Down