def is_sorted_periodic(lst):
    """Used to verify that seasons provided to SeasonResampler are in order."""
    n = len(lst)

    # Find the wraparound point where the list decreases
    wrap_point = -1
    for i in range(1, n):
        if lst[i] < lst[i - 1]:
            wrap_point = i
            break

    # If no wraparound point is found, the list is already sorted
    if wrap_point == -1:
        return True

    # Check if both parts around the wrap point are sorted
    for i in range(1, wrap_point):
        if lst[i] < lst[i - 1]:
            return False
    for i in range(wrap_point + 1, n):
        if lst[i] < lst[i - 1]:
            return False

    # Check wraparound condition
    return lst[-1] <= lst[0]
Used to verify that seasons provided to SeasonResampler are in order.
xarray/groupers.py