Skip to content

Commit

Permalink
Add explaination of code for spanning months
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Mar 6, 2023
1 parent 3a97d99 commit 81bb84d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion xcdat/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,11 +1393,17 @@ def _shift_spanning_months(self, df: pd.DataFrame) -> pd.DataFrame:
custom_seasons = self._season_config["custom_seasons"]

span_months: List[int] = []

# Loop over the custom seasons and get the list of months for the
# current season. Convert those months to their integer representations.
# If 1 ("Jan") is in the list of months and it is NOT the first element,
# then get all elements before it (aka the spanning months).
for months in custom_seasons.values(): # type: ignore
month_nums = [MONTH_STR_TO_INT[month] for month in months]
try:
jan_index = month_nums.index(1)
span_months = span_months + month_nums[:jan_index]
if jan_index != 0:
span_months = span_months + month_nums[:jan_index]
break
except ValueError:
continue
Expand Down

0 comments on commit 81bb84d

Please sign in to comment.