|
| 1 | +from pandas import Series |
| 2 | +import pandas.util.testing as tm |
| 3 | + |
| 4 | + |
| 5 | +def test_original_ordering_value_counts(): |
| 6 | + # All items occour exactly once. No matter if sorted or not, the resulting |
| 7 | + # values should be in the same order. |
| 8 | + s = Series(list('bacdef')) |
| 9 | + |
| 10 | + # Garantee the same index if value_counts(sort=False) is used |
| 11 | + vc = s.value_counts(sort=False, ascending=False) |
| 12 | + tm.assert_series_equal(Series(vc.index), s) |
| 13 | + |
| 14 | + vc = s.value_counts(sort=True, ascending=False) |
| 15 | + tm.assert_series_equal(Series(vc.index), s) |
| 16 | + |
| 17 | + |
| 18 | +def test_original_ordering_value_counts2(): |
| 19 | + # 'a' is there twice. Sorted, it should be there at the top, unsorted it |
| 20 | + # should stay where it is. |
| 21 | + s = Series(list('bacaef')) |
| 22 | + ref_nonsorted = Series(list('bacef')) |
| 23 | + ref_sorted = Series(list('abcef')) |
| 24 | + |
| 25 | + # Garantee the same index if value_counts(sort=False) is used |
| 26 | + vc = s.value_counts(sort=False, ascending=False) |
| 27 | + tm.assert_series_equal(Series(vc.index), ref_nonsorted) |
| 28 | + |
| 29 | + vc = s.value_counts(sort=True, ascending=False) |
| 30 | + tm.assert_series_equal(Series(vc.index), ref_sorted) |
| 31 | + |
| 32 | + |
| 33 | +def test_original_ordering_value_counts_ascending(): |
| 34 | + # All items occour exactly once. No matter if sorted or not, the resulting |
| 35 | + # values should be in the same order. |
| 36 | + s = Series(list('bacdef')) |
| 37 | + |
| 38 | + # Garantee the same index if value_counts(sort=False) is used |
| 39 | + vc = s.value_counts(sort=False, ascending=True) |
| 40 | + tm.assert_series_equal(Series(vc.index), s) |
| 41 | + |
| 42 | + vc = s.value_counts(sort=True, ascending=True) |
| 43 | + tm.assert_series_equal(Series(vc.index), s) |
| 44 | + |
| 45 | + |
| 46 | +def test_original_ordering_value_counts_ascending2(): |
| 47 | + # 'a' is there twice. Unsorted, it should be there at the bottom, unsorted |
| 48 | + # it should stay where it is. |
| 49 | + s = Series(list('bacaef')) |
| 50 | + ref_nonsorted = Series(list('bacef')) |
| 51 | + ref_sorted = Series(list('bcefa')) |
| 52 | + |
| 53 | + # Garantee the same index if value_counts(sort=False) is used |
| 54 | + vc = s.value_counts(sort=False, ascending=True) |
| 55 | + tm.assert_series_equal(Series(vc.index), ref_nonsorted) |
| 56 | + |
| 57 | + vc = s.value_counts(sort=True, ascending=True) |
| 58 | + tm.assert_series_equal(Series(vc.index), ref_sorted) |
0 commit comments