Skip to content

Commit e966aa7

Browse files
committed
Modularize value_counts tests and xfail sort=True ones
1 parent c857119 commit e966aa7

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

pandas/tests/test_algos.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -962,41 +962,51 @@ 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(self):
965+
def test_value_counts_nonsorted_single_occurance(self):
966+
# GH 12679
966967
# All items occour exactly once.
967968
# No matter if sorted or not, the resulting values should be in
968969
# the same order.
969970
s = Series(list('bacdef'))
970971

971-
# Garantee the same index if value_counts(sort=False) is used
972+
# Guarantee the same index if value_counts(sort=False) is used
972973
vc = s.value_counts(sort=False, ascending=False)
973974
tm.assert_series_equal(Series(vc.index), s)
974975
vc = s.value_counts(sort=False, ascending=True)
975976
tm.assert_series_equal(Series(vc.index), s)
976977

977-
# Garantee does not hold yet for the sort=True case
978-
# vc = s.value_counts(sort=True, ascending=False)
979-
# tm.assert_series_equal(Series(vc.index), s)
980-
# vc = s.value_counts(sort=True, ascending=True)
981-
# tm.assert_series_equal(Series(vc.index), s)
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)
982987

988+
def test_value_counts_nonsorted_double_occurance(self):
989+
# GH 12679
983990
# 'a' is there twice. Sorted, it should be there at the top.
984-
# Unsorted it should stay where it is.
985991
s = Series(list('bacaef'))
986992
ref_nonsorted = Series(list('bacef'))
987-
ref_sorted = Series(list('abcef'))
988993

989-
# Garantee the same index if value_counts(sort=False) is used
994+
# Guarantee the same index if value_counts(sort=False) is used
990995
vc = s.value_counts(sort=False, ascending=False)
991996
tm.assert_series_equal(Series(vc.index), ref_nonsorted)
992997
vc = s.value_counts(sort=False, ascending=True)
993998
tm.assert_series_equal(Series(vc.index), ref_nonsorted)
994999

995-
# Garantee does not hold yet for the sort=True case
996-
# vc = s.value_counts(sort=True, ascending=False)
997-
# tm.assert_series_equal(Series(vc.index), ref_sorted)
998-
# vc = s.value_counts(sort=True, ascending=True)
999-
# tm.assert_series_equal(Series(vc.index), ref_sorted)
1000+
@pytest.mark.xfail(reason="sort=True does not guarantee the same order")
1001+
def test_value_counts_sorted_double_occurance(self):
1002+
# GH 12679
1003+
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)
10001010

10011011

10021012
class TestDuplicated(object):

0 commit comments

Comments
 (0)