Skip to content

Commit 33cfff4

Browse files
committed
fix(RiskPCalc): sorts the snapshots
1 parent bc38525 commit 33cfff4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

climada/trajectories/risk_trajectory.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(
100100
impact_computation_strategy or ImpactCalcComputation()
101101
)
102102
LOGGER.debug("Computing risk periods")
103-
self._risk_periods_calculators = self._calc_risk_periods(snapshots_list)
103+
self._risk_periods_calculators = None
104104

105105
def _reset_metrics(self):
106106
for metric in POSSIBLE_METRICS:
@@ -168,7 +168,7 @@ def risk_transf_attach(self, value):
168168
@property
169169
def risk_periods(self) -> list:
170170
"""The computed risk periods from the snapshots."""
171-
if not self._risk_period_up_to_date:
171+
if self._risk_period_up_to_date is None or not self._risk_period_up_to_date:
172172
self._risk_periods_calculators = self._calc_risk_periods(self._snapshots)
173173
self._risk_period_up_to_date = True
174174

@@ -211,7 +211,9 @@ def pairwise(container: list):
211211
risk_transf_attach=self.risk_transf_attach,
212212
calc_residual=self._calc_residual,
213213
)
214-
for start_snapshot, end_snapshot in pairwise(snapshots)
214+
for start_snapshot, end_snapshot in pairwise(
215+
sorted(snapshots, key=lambda snap: snap.date)
216+
)
215217
]
216218

217219
@classmethod

0 commit comments

Comments
 (0)