|
| 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) |
| 12 | + tm.assert_series_equal(Series(vc.index), s) |
| 13 | + |
| 14 | + |
| 15 | +def test_original_ordering_value_counts2(): |
| 16 | + # 'a' is there twice. Unsorted, it should be there at the top, unsorted it |
| 17 | + # should stay where it is. |
| 18 | + s = Series(list('bacaef')) |
| 19 | + ref_nonsorted = Series(list('bacef')) |
| 20 | + |
| 21 | + # Garantee the same index if value_counts(sort=False) is used |
| 22 | + vc = s.value_counts(sort=False) |
| 23 | + tm.assert_series_equal(Series(vc.index), ref_nonsorted) |
| 24 | + |
| 25 | + |
| 26 | +def test_original_ordering_value_counts_ascending(): |
| 27 | + # All items occour exactly once. No matter if sorted or not, the resulting |
| 28 | + # values should be in the same order. |
| 29 | + s = Series(list('bacdef')) |
| 30 | + |
| 31 | + # Garantee the same index if value_counts(sort=False) is used |
| 32 | + vc = s.value_counts(sort=False, ascending=True) |
| 33 | + tm.assert_series_equal(Series(vc.index), s) |
| 34 | + |
| 35 | + |
| 36 | +def test_original_ordering_value_counts_ascending2(): |
| 37 | + # 'a' is there twice. Unsorted, it should be there at the bottom, unsorted it |
| 38 | + # should stay where it is. |
| 39 | + s = Series(list('bacaef')) |
| 40 | + ref = Series(list('bacef')) |
| 41 | + |
| 42 | + # Garantee the same index if value_counts(sort=False) is used |
| 43 | + vc = s.value_counts(sort=False, ascending=True) |
| 44 | + tm.assert_series_equal(Series(vc.index), ref) |
0 commit comments