MCPcopy Index your code
hub / github.com/pydata/xarray / is_sorted_periodic

Function is_sorted_periodic

xarray/groupers.py:721–745  ·  view source on GitHub ↗

Used to verify that seasons provided to SeasonResampler are in order.

(lst)

Source from the content-addressed store, hash-verified

719
720
721def 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)

Callers 1

__post_init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…