Skip to content

Commit 21cc433

Browse files
committed
Improves for CB
1 parent 5ab8bda commit 21cc433

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

climada/trajectories/risk_trajectory.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,19 @@ def _date_to_period_agg(
534534
## I'm thinking this does not work with RPs... As you can't just sum impacts
535535
## Not sure what to do with it. -> Fixed I take the avg RP impact of the period
536536
def conditional_agg(group):
537-
if "rp" in group.name[2]:
538-
return group.mean()
539-
else:
537+
try:
538+
if "rp" in group.name[2]:
539+
return group.mean()
540+
else:
541+
return group.sum()
542+
except IndexError:
540543
return group.sum()
541544

545+
df_sorted = df.sort_values(by=grouper + ["date"])
546+
542547
if "group" in df.columns and "group" not in grouper:
543548
grouper = ["group"] + grouper
544549

545-
df_sorted = df.sort_values(by=cls._grouper + ["date"])
546550
# Apply the function to identify continuous periods
547551
df_periods = df_sorted.groupby(
548552
grouper, dropna=False, group_keys=False, observed=True

0 commit comments

Comments
 (0)