Used to verify that seasons provided to SeasonResampler are in order.
(lst)
| 719 | |
| 720 | |
| 721 | def is_sorted_periodic(lst): |
| 722 | """Used to verify that seasons provided to SeasonResampler are in order.""" |
| 723 | n = len(lst) |
| 724 | |
| 725 | # Find the wraparound point where the list decreases |
| 726 | wrap_point = -1 |
| 727 | for i in range(1, n): |
| 728 | if lst[i] < lst[i - 1]: |
| 729 | wrap_point = i |
| 730 | break |
| 731 | |
| 732 | # If no wraparound point is found, the list is already sorted |
| 733 | if wrap_point == -1: |
| 734 | return True |
| 735 | |
| 736 | # Check if both parts around the wrap point are sorted |
| 737 | for i in range(1, wrap_point): |
| 738 | if lst[i] < lst[i - 1]: |
| 739 | return False |
| 740 | for i in range(wrap_point + 1, n): |
| 741 | if lst[i] < lst[i - 1]: |
| 742 | return False |
| 743 | |
| 744 | # Check wraparound condition |
| 745 | return lst[-1] <= lst[0] |
| 746 | |
| 747 | |
| 748 | @dataclass(kw_only=True, frozen=True) |
no outgoing calls
no test coverage detected
searching dependent graphs…