Skip to content

Commit 59c5be2

Browse files
authored
Parametrized groupby allowlist test (#38829)
1 parent 4edb52b commit 59c5be2

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

pandas/tests/groupby/test_allowlist.py

+34-18
Original file line numberDiff line numberDiff line change
@@ -341,18 +341,9 @@ def test_groupby_function_rename(mframe):
341341
assert f.__name__ == name
342342

343343

344-
@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
345-
def test_groupby_selection_with_methods(df):
346-
# some methods which require DatetimeIndex
347-
rng = date_range("2014", periods=len(df))
348-
df.index = rng
349-
350-
g = df.groupby(["A"])[["C"]]
351-
g_exp = df[["C"]].groupby(df["A"])
352-
# TODO check groupby with > 1 col ?
353-
354-
# methods which are called as .foo()
355-
methods = [
344+
@pytest.mark.parametrize(
345+
"method",
346+
[
356347
"count",
357348
"corr",
358349
"cummax",
@@ -370,20 +361,45 @@ def test_groupby_selection_with_methods(df):
370361
"ffill",
371362
"bfill",
372363
"pct_change",
373-
]
364+
],
365+
)
366+
def test_groupby_selection_with_methods(df, method):
367+
# some methods which require DatetimeIndex
368+
rng = date_range("2014", periods=len(df))
369+
df.index = rng
374370

375-
for m in methods:
376-
res = getattr(g, m)()
377-
exp = getattr(g_exp, m)()
371+
g = df.groupby(["A"])[["C"]]
372+
g_exp = df[["C"]].groupby(df["A"])
373+
# TODO check groupby with > 1 col ?
378374

379-
# should always be frames!
380-
tm.assert_frame_equal(res, exp)
375+
res = getattr(g, method)()
376+
exp = getattr(g_exp, method)()
377+
378+
# should always be frames!
379+
tm.assert_frame_equal(res, exp)
380+
381+
382+
@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
383+
def test_groupby_selection_tshift_raises(df):
384+
rng = date_range("2014", periods=len(df))
385+
df.index = rng
386+
387+
g = df.groupby(["A"])[["C"]]
381388

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

394+
395+
def test_groupby_selection_other_methods(df):
396+
# some methods which require DatetimeIndex
397+
rng = date_range("2014", periods=len(df))
398+
df.index = rng
399+
400+
g = df.groupby(["A"])[["C"]]
401+
g_exp = df[["C"]].groupby(df["A"])
402+
387403
# methods which aren't just .foo()
388404
tm.assert_frame_equal(g.fillna(0), g_exp.fillna(0))
389405
tm.assert_frame_equal(g.dtypes, g_exp.dtypes)

0 commit comments

Comments
 (0)