Skip to content

Commit 658ea54

Browse files
rhshadrachim-vinicius
authored and
im-vinicius
committed
TST/CLN: Remove groupby.test_allowlist (pandas-dev#52880)
1 parent 16d9c39 commit 658ea54

File tree

3 files changed

+112
-124
lines changed

3 files changed

+112
-124
lines changed

pandas/tests/groupby/test_allowlist.py

-124
This file was deleted.

pandas/tests/groupby/test_function.py

+50
Original file line numberDiff line numberDiff line change
@@ -1662,3 +1662,53 @@ def test_duplicate_columns(request, groupby_func, as_index):
16621662
if groupby_func not in ("size", "ngroup", "cumcount"):
16631663
expected = expected.rename(columns={"c": "b"})
16641664
tm.assert_equal(result, expected)
1665+
1666+
1667+
@pytest.mark.parametrize(
1668+
"op",
1669+
[
1670+
"sum",
1671+
"prod",
1672+
"min",
1673+
"max",
1674+
"median",
1675+
"mean",
1676+
"skew",
1677+
"std",
1678+
"var",
1679+
"sem",
1680+
],
1681+
)
1682+
@pytest.mark.parametrize("axis", [0, 1])
1683+
@pytest.mark.parametrize("skipna", [True, False])
1684+
@pytest.mark.parametrize("sort", [True, False])
1685+
def test_regression_allowlist_methods(op, axis, skipna, sort):
1686+
# GH6944
1687+
# GH 17537
1688+
# explicitly test the allowlist methods
1689+
raw_frame = DataFrame([0])
1690+
if axis == 0:
1691+
frame = raw_frame
1692+
msg = "The 'axis' keyword in DataFrame.groupby is deprecated and will be"
1693+
else:
1694+
frame = raw_frame.T
1695+
msg = "DataFrame.groupby with axis=1 is deprecated"
1696+
1697+
with tm.assert_produces_warning(FutureWarning, match=msg):
1698+
grouped = frame.groupby(level=0, axis=axis, sort=sort)
1699+
1700+
if op == "skew":
1701+
# skew has skipna
1702+
result = getattr(grouped, op)(skipna=skipna)
1703+
expected = frame.groupby(level=0).apply(
1704+
lambda h: getattr(h, op)(axis=axis, skipna=skipna)
1705+
)
1706+
if sort:
1707+
expected = expected.sort_index(axis=axis)
1708+
tm.assert_frame_equal(result, expected)
1709+
else:
1710+
result = getattr(grouped, op)()
1711+
expected = frame.groupby(level=0).apply(lambda h: getattr(h, op)(axis=axis))
1712+
if sort:
1713+
expected = expected.sort_index(axis=axis)
1714+
tm.assert_frame_equal(result, expected)

pandas/tests/groupby/test_groupby.py

+62
Original file line numberDiff line numberDiff line change
@@ -2981,3 +2981,65 @@ def test_groupby_sum_on_nan_should_return_nan(bug_var):
29812981

29822982
expected_df = DataFrame([bug_var, bug_var, bug_var, np.nan], columns=["A"])
29832983
tm.assert_frame_equal(result, expected_df)
2984+
2985+
2986+
@pytest.mark.parametrize(
2987+
"method",
2988+
[
2989+
"count",
2990+
"corr",
2991+
"cummax",
2992+
"cummin",
2993+
"cumprod",
2994+
"describe",
2995+
"rank",
2996+
"quantile",
2997+
"diff",
2998+
"shift",
2999+
"all",
3000+
"any",
3001+
"idxmin",
3002+
"idxmax",
3003+
"ffill",
3004+
"bfill",
3005+
"pct_change",
3006+
],
3007+
)
3008+
def test_groupby_selection_with_methods(df, method):
3009+
# some methods which require DatetimeIndex
3010+
rng = date_range("2014", periods=len(df))
3011+
df.index = rng
3012+
3013+
g = df.groupby(["A"])[["C"]]
3014+
g_exp = df[["C"]].groupby(df["A"])
3015+
# TODO check groupby with > 1 col ?
3016+
3017+
res = getattr(g, method)()
3018+
exp = getattr(g_exp, method)()
3019+
3020+
# should always be frames!
3021+
tm.assert_frame_equal(res, exp)
3022+
3023+
3024+
def test_groupby_selection_other_methods(df):
3025+
# some methods which require DatetimeIndex
3026+
rng = date_range("2014", periods=len(df))
3027+
df.columns.name = "foo"
3028+
df.index = rng
3029+
3030+
g = df.groupby(["A"])[["C"]]
3031+
g_exp = df[["C"]].groupby(df["A"])
3032+
3033+
# methods which aren't just .foo()
3034+
tm.assert_frame_equal(g.fillna(0), g_exp.fillna(0))
3035+
msg = "DataFrameGroupBy.dtypes is deprecated"
3036+
with tm.assert_produces_warning(FutureWarning, match=msg):
3037+
tm.assert_frame_equal(g.dtypes, g_exp.dtypes)
3038+
tm.assert_frame_equal(g.apply(lambda x: x.sum()), g_exp.apply(lambda x: x.sum()))
3039+
3040+
tm.assert_frame_equal(g.resample("D").mean(), g_exp.resample("D").mean())
3041+
tm.assert_frame_equal(g.resample("D").ohlc(), g_exp.resample("D").ohlc())
3042+
3043+
tm.assert_frame_equal(
3044+
g.filter(lambda x: len(x) == 3), g_exp.filter(lambda x: len(x) == 3)
3045+
)

0 commit comments

Comments
 (0)