Skip to content

Commit c80af01

Browse files
dsaxtonproost
authored andcommitted
REF: Parametrize value_counts tests (pandas-dev#28537)
1 parent 1b91eeb commit c80af01

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

pandas/tests/groupby/test_value_counts.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,30 @@ def seed_df(seed_nans, n, m):
5252

5353
@pytest.mark.slow
5454
@pytest.mark.parametrize("df, keys, bins, n, m", binned, ids=ids)
55-
def test_series_groupby_value_counts(df, keys, bins, n, m):
55+
@pytest.mark.parametrize("isort", [True, False])
56+
@pytest.mark.parametrize("normalize", [True, False])
57+
@pytest.mark.parametrize("sort", [True, False])
58+
@pytest.mark.parametrize("ascending", [True, False])
59+
@pytest.mark.parametrize("dropna", [True, False])
60+
def test_series_groupby_value_counts(
61+
df, keys, bins, n, m, isort, normalize, sort, ascending, dropna
62+
):
5663
def rebuild_index(df):
5764
arr = list(map(df.index.get_level_values, range(df.index.nlevels)))
5865
df.index = MultiIndex.from_arrays(arr, names=df.index.names)
5966
return df
6067

61-
for isort, normalize, sort, ascending, dropna in product((False, True), repeat=5):
62-
63-
kwargs = dict(
64-
normalize=normalize,
65-
sort=sort,
66-
ascending=ascending,
67-
dropna=dropna,
68-
bins=bins,
69-
)
68+
kwargs = dict(
69+
normalize=normalize, sort=sort, ascending=ascending, dropna=dropna, bins=bins
70+
)
7071

71-
gr = df.groupby(keys, sort=isort)
72-
left = gr["3rd"].value_counts(**kwargs)
72+
gr = df.groupby(keys, sort=isort)
73+
left = gr["3rd"].value_counts(**kwargs)
7374

74-
gr = df.groupby(keys, sort=isort)
75-
right = gr["3rd"].apply(Series.value_counts, **kwargs)
76-
right.index.names = right.index.names[:-1] + ["3rd"]
75+
gr = df.groupby(keys, sort=isort)
76+
right = gr["3rd"].apply(Series.value_counts, **kwargs)
77+
right.index.names = right.index.names[:-1] + ["3rd"]
7778

78-
# have to sort on index because of unstable sort on values
79-
left, right = map(rebuild_index, (left, right)) # xref GH9212
80-
tm.assert_series_equal(left.sort_index(), right.sort_index())
79+
# have to sort on index because of unstable sort on values
80+
left, right = map(rebuild_index, (left, right)) # xref GH9212
81+
tm.assert_series_equal(left.sort_index(), right.sort_index())

0 commit comments

Comments
 (0)