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 Apr 4, 2024
1 parent aada458 commit 3a53f14
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 @@ -1547,11 +1547,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 3a53f14

Please sign in to comment.