test_monotonic.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from pandas import (
  2. Period,
  3. PeriodIndex,
  4. )
  5. def test_is_monotonic_increasing():
  6. # GH#17717
  7. p0 = Period("2017-09-01")
  8. p1 = Period("2017-09-02")
  9. p2 = Period("2017-09-03")
  10. idx_inc0 = PeriodIndex([p0, p1, p2])
  11. idx_inc1 = PeriodIndex([p0, p1, p1])
  12. idx_dec0 = PeriodIndex([p2, p1, p0])
  13. idx_dec1 = PeriodIndex([p2, p1, p1])
  14. idx = PeriodIndex([p1, p2, p0])
  15. assert idx_inc0.is_monotonic_increasing is True
  16. assert idx_inc1.is_monotonic_increasing is True
  17. assert idx_dec0.is_monotonic_increasing is False
  18. assert idx_dec1.is_monotonic_increasing is False
  19. assert idx.is_monotonic_increasing is False
  20. def test_is_monotonic_decreasing():
  21. # GH#17717
  22. p0 = Period("2017-09-01")
  23. p1 = Period("2017-09-02")
  24. p2 = Period("2017-09-03")
  25. idx_inc0 = PeriodIndex([p0, p1, p2])
  26. idx_inc1 = PeriodIndex([p0, p1, p1])
  27. idx_dec0 = PeriodIndex([p2, p1, p0])
  28. idx_dec1 = PeriodIndex([p2, p1, p1])
  29. idx = PeriodIndex([p1, p2, p0])
  30. assert idx_inc0.is_monotonic_decreasing is False
  31. assert idx_inc1.is_monotonic_decreasing is False
  32. assert idx_dec0.is_monotonic_decreasing is True
  33. assert idx_dec1.is_monotonic_decreasing is True
  34. assert idx.is_monotonic_decreasing is False