Skip to content

Commit 6eaf095

Browse files
committed
less confusing naming
1 parent 3609471 commit 6eaf095

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

climada/trajectories/risk_trajectory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def _compute_period_metrics(
288288
df = self._generic_metrics(
289289
npv=npv, metric_name=metric_name, metric_meth=metric_meth, **kwargs
290290
)
291-
return self._per_period_risk(df)
291+
return self._date_to_period_agg(df)
292292

293293
def _compute_metrics(
294294
self, metric_name: str, metric_meth: str, npv: bool = True, **kwargs
@@ -507,7 +507,7 @@ def _get_risk_periods(
507507
]
508508

509509
@classmethod
510-
def _per_period_risk(
510+
def _date_to_period_agg(
511511
cls,
512512
df: pd.DataFrame,
513513
time_unit: str = "year",
@@ -588,7 +588,7 @@ def per_period_risk_metrics(
588588
) -> pd.DataFrame | pd.Series:
589589
"""Returns a tidy dataframe of the risk metrics with the total for each different period."""
590590
df = self.per_date_risk_metrics(metrics=metrics, **kwargs)
591-
return self._per_period_risk(df, **kwargs)
591+
return self._date_to_period_agg(df, **kwargs)
592592

593593
def _calc_waterfall_plot_data(
594594
self,

climada/trajectories/test/test_risk_trajectory.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def test_per_period_risk_basic(self):
631631
"risk": [100.0, 200.0, 300.0, 50.0],
632632
}
633633
)
634-
result_df = RiskTrajectory._per_period_risk(df_input)
634+
result_df = RiskTrajectory._date_to_period_agg(df_input)
635635

636636
expected_df = pd.DataFrame(
637637
{
@@ -659,7 +659,7 @@ def test_per_period_risk_multiple_risk_cols(self):
659659
"exposure contribution": [5.0, 8.0],
660660
}
661661
)
662-
result_df = RiskTrajectory._per_period_risk(
662+
result_df = RiskTrajectory._date_to_period_agg(
663663
df_input, colname=["base risk", "exposure contribution"]
664664
)
665665

@@ -686,7 +686,9 @@ def test_per_period_risk_non_yearly_intervals(self):
686686
}
687687
)
688688
# Test with 'month' time_unit
689-
result_df_month = RiskTrajectory._per_period_risk(df_input, time_unit="month")
689+
result_df_month = RiskTrajectory._date_to_period_agg(
690+
df_input, time_unit="month"
691+
)
690692
expected_df_month = pd.DataFrame(
691693
{
692694
"period": ["2023-01-01 to 2023-03-01"],
@@ -710,7 +712,7 @@ def test_per_period_risk_non_yearly_intervals(self):
710712
"risk": [10.0, 20.0, 40.0],
711713
}
712714
)
713-
result_df_gap = RiskTrajectory._per_period_risk(df_gap, time_unit="month")
715+
result_df_gap = RiskTrajectory._date_to_period_agg(df_gap, time_unit="month")
714716
expected_df_gap = pd.DataFrame(
715717
{
716718
"period": ["2023-01-01 to 2023-02-01", "2023-04-01 to 2023-04-01"],

0 commit comments

Comments
 (0)