Skip to content

Commit 355f872

Browse files
committed
Parametrize value_counts test
1 parent 405ac0e commit 355f872

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

pandas/tests/test_algos.py

+20-30
Original file line numberDiff line numberDiff line change
@@ -962,51 +962,41 @@ def test_value_counts_uint64(self):
962962
if not compat.is_platform_32bit():
963963
tm.assert_series_equal(result, expected)
964964

965-
def test_value_counts_nonsorted_single_occurance(self):
965+
@pytest.mark.parametrize("sort",
966+
[pytest.param(True, marks=pytest.mark.xfail), False])
967+
@pytest.mark.parametrize("ascending", [True, False])
968+
def test_value_counts_single_occurance(self, sort, ascending):
966969
# GH 12679
967970
# All items occour exactly once.
968971
# No matter if sorted or not, the resulting values should be in
969972
# the same order.
970-
s = Series(list('bacdef'))
973+
expected = Series(list('bacdef'))
971974

972975
# Guarantee the same index if value_counts(sort=False) is used
973-
vc = s.value_counts(sort=False, ascending=False)
974-
tm.assert_series_equal(Series(vc.index), s)
975-
vc = s.value_counts(sort=False, ascending=True)
976-
tm.assert_series_equal(Series(vc.index), s)
976+
vc = expected.value_counts(sort=sort, ascending=ascending)
977+
result = Series(vc.index)
978+
tm.assert_series_equal(result, expected)
977979

978-
@pytest.mark.xfail(reason="sort=True does not guarantee the same order")
979-
def test_value_counts_sorted_single_occurance(self):
980-
# GH 12679
981-
s = Series(list('bacdef'))
982-
# Guarantee does not hold yet for the sort=True case
983-
vc = s.value_counts(sort=True, ascending=False)
984-
tm.assert_series_equal(Series(vc.index), s)
985-
vc = s.value_counts(sort=True, ascending=True)
986-
tm.assert_series_equal(Series(vc.index), s)
987-
988-
def test_value_counts_nonsorted_double_occurance(self):
980+
@pytest.mark.parametrize("ascending", [True, False])
981+
def test_value_counts_nonsorted_double_occurance(self, ascending):
989982
# GH 12679
990983
# 'a' is there twice. Sorted, it should be there at the top.
991984
s = Series(list('bacaef'))
992-
ref_nonsorted = Series(list('bacef'))
985+
expected = Series(list('bacef'))
993986

994-
# Guarantee the same index if value_counts(sort=False) is used
995-
vc = s.value_counts(sort=False, ascending=False)
996-
tm.assert_series_equal(Series(vc.index), ref_nonsorted)
997-
vc = s.value_counts(sort=False, ascending=True)
998-
tm.assert_series_equal(Series(vc.index), ref_nonsorted)
987+
vc = s.value_counts(sort=False, ascending=ascending)
988+
result = Series(vc.index)
989+
tm.assert_series_equal(result, expected)
999990

991+
@pytest.mark.parametrize("ascending, expected",
992+
[(True, Series(list('abcef'))),
993+
(False, Series(list('bcefa')))])
1000994
@pytest.mark.xfail(reason="sort=True does not guarantee the same order")
1001-
def test_value_counts_sorted_double_occurance(self):
995+
def test_value_counts_sorted_double_occurance(self, ascending, expected):
1002996
# GH 12679
1003997
s = Series(list('bacaef'))
1004-
ref_sorted = Series(list('abcef'))
1005-
# Guarantee does not hold yet for the sort=True case
1006-
vc = s.value_counts(sort=True, ascending=False)
1007-
tm.assert_series_equal(Series(vc.index), ref_sorted)
1008-
vc = s.value_counts(sort=True, ascending=True)
1009-
tm.assert_series_equal(Series(vc.index), ref_sorted)
998+
vc = s.value_counts(sort=True, ascending=ascending)
999+
tm.assert_series_equal(Series(vc.index), expected)
10101000

10111001

10121002
class TestDuplicated(object):

0 commit comments

Comments
 (0)